I need to add the file to the repository and then commit it from my java project. I use
Runtime.getRuntime().exec("C:\\Program Files (x86)\\Git\\bin\\sh.exe");
to start git but what should I do next?
Instead of running the command line tool directly from your Java application, consider using Git APIs for Java, such as JavaGit. The cookbook has examples that you can follow.
I code should be something like this:
public void gitCommands() throws IOException {
// Build command
List<String> commands = new ArrayList<String>();
commands.add("/bin/bash");
commands.add("-c");
commands.add("git add .");
StringBuilder out = new StringBuilder();
ProcessBuilder pb = new ProcessBuilder(commands);
pb.redirectErrorStream(true);
process process = pb.start();
//EDIT:
// get Exit Status
process.waitFor();
//go for next commands
.....
}
sh.exe isn't Git, it's the command shell distributed with Git. You'd want to run Git directly, e.g. like this:
String[] command = {"C:\\Program Files (x86)\\Git\\bin\\git.exe",
"add",
"some-file-to-add"};
Runtime.getRuntime().exec(command);
But since you're writing in Java I suggest you have a look at JGit, a native Java Git library.