I'm trying to create a directory and initialize it as a git repository using javagit library. Below is the code snippet that i'm using:
repositoryDirectory = FileUtilities.createTempDirectory("C:/Madhu/ReleaseManagerRepo/Demo_gitRepository");
System.out.println("Git Repository Location : " + repositoryDirectory.getAbsolutePath());
//get the instance of the dotGit Object
dotGit = DotGit.getInstance(repositoryDirectory);
System.out.println("DotGit==========="+dotGit.toString());
//Initialize the repository ,similar to git init
dotGit.init();
I can see that the directory is created. After the dotGit.init() is executed, i don't see a .git (which i get when i run the command git init from command line.) directory under the directory specified in the code.
My second question is i'm trying to create a file from my code and want to add it to the git repository. Below is the code snippet for the same:
File file = FileUtilities.createFile(repositoryDirectory, "README", "First file in the git repository");
//get the current working tree from the git repository
WorkingTree wt = dotGit.getWorkingTree();
GitAddResponse ar = wt.add();
wt.commitAll("First commit to the git repository");
I'm getting an exception as below:
Exception in thread "main" java.io.IOException: 020100: Unable to start sub-process.
at edu.nyu.cs.javagit.client.cli.ProcessUtilities.startProcess(ProcessUtilities.java:50)
at edu.nyu.cs.javagit.client.cli.ProcessUtilities.runCommand(ProcessUtilities.java:141)
at edu.nyu.cs.javagit.client.cli.CliGitAdd.add(CliGitAdd.java:49)
at edu.nyu.cs.javagit.api.commands.GitAdd.add(GitAdd.java:67)
at edu.nyu.cs.javagit.api.GitFileSystemObject.add(GitFileSystemObject.java:185)
at edu.nyu.cs.javagit.api.WorkingTree.add(WorkingTree.java:130)
at javagit.JavaGitDemo.main(JavaGitDemo.java:41)
Caused by: java.io.IOException: CreateProcess: git add C:\Madhu\ReleaseManagerRepo\Demo_gitRepository\README error=2
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at edu.nyu.cs.javagit.client.cli.ProcessUtilities.startProcess(ProcessUtilities.java:48)
... 6 more
I have added the git/bin to my Path environment variable. But i still see the same exception. I'm not sure if i'm missing on anything else.
Could you please suggest.
Regards, Madhusudhan.