我正在尝试使用javagit库创建一个目录并将其初始化为git存储库。 以下是我正在使用的代码段:
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();
我可以看到该目录已创建。在执行dotGit.init()之后,我没有看到.git(我从命令行运行命令git init时得到的。)目录在代码中指定的目录下。
我的第二个问题是我正在尝试从我的代码创建一个文件,并希望将其添加到git存储库。以下是相同的代码段:
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");
我得到如下例外情况:
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
我已将git / bin添加到Path环境变量中。但我仍然看到同样的例外。我不确定我是否缺少其他任何东西。
请你建议。
此致 Madhusudhan。