2

For a project, I need to take a list of git commit Id's (A couple thousand), and compare them two at a time, saving specific information from the return into a file. The only issue I'm having is getting a diff command to work in Java. I've spend hours trying to figure this out and I'm still in need of assistance.

1
  • 1
    I suppose you used java.lang.ProcessBuilder. What was the problem ? What's your OS ? Commented Jun 7, 2012 at 15:00

1 Answer 1

3

You can run a command and get its result using this :

    ProcessBuilder processBuilder = new ProcessBuilder(command);
    processBuilder.redirectErrorStream(true);
    Process process = processBuilder.start();
    String output = readOutput(process);
    try {
        if (process.waitFor() != 0) {
            throw new IOException(
                "command exited in error: " + process.exitValue()
                    + "\n" + output);
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return output;

So you just have to define the most adapted "git diff..." command for your problem and parse the output.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.