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 Answer
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.