有没有办法像所有其他更改一样处理子存储库中的更改?在命令行上我通常会这样做:
git add subrepo/
但这似乎不适用于JGit ......
编辑: 这是我尝试过的一些代码。 displayStatus方法类似于https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ShowStatus.java
public void testSubmoduleHandling(File worktree)
{
Repository repository = null;
Repository subrepo = null;
try
{
worktree.mkdir();
File file;
String filename1 = "file1";
filename1 = TranscodeHelper.convertJavaToShell(filename1);
file = new File(worktree, filename1);
file.createNewFile();
String filename2 = "file2";
filename2 = TranscodeHelper.convertJavaToShell(filename2);
file = new File(worktree, filename2);
file.createNewFile();
String subworktreename = "subrepo";
subworktreename = TranscodeHelper.convertJavaToShell(subworktreename);
File subworktree = new File(worktree, subworktreename);
subworktree.mkdir();
String subfilename1 = "subfile1";
subfilename1 = TranscodeHelper.convertJavaToShell(subfilename1);
File subfile1 = new File(subworktree, subfilename1);
subfile1.createNewFile();
repository = createNewRepoAt(worktree);
Git git = new Git(repository);
subrepo = createNewRepoAt(subworktree);
Git subgit = new Git(subrepo);
subgit.add().addFilepattern(subfilename1);
subgit.commit().setCommitter(ich).setAuthor(ich).setMessage("Erstcommit").call();
git.add().addFilepattern(subworktreename + "/");
git.commit().setCommitter(ich).setAuthor(ich).setMessage("Subrepo").call();
// git.add().addFilepattern(".").call();
// git.commit().setCommitter(ich).setAuthor(ich).setMessage("Full").call();
String subfilename2 = "subfile2";
subfilename2 = TranscodeHelper.convertJavaToShell(subfilename2);
File subfile2 = new File(subworktree, subfilename2);
subfile2.createNewFile();
displayStatus(git, "Nach Erstcommits");
}
catch (Exception e)
{
ctx.out().println(e.getClass().getName());
ctx.out().println(e);
throw new RuntimeException(e);
}
finally
{
if (repository != null) repository.close();
if (subrepo != null) subrepo.close();
try
{
//FileUtils.deleteDirectory(worktree);
}
catch (Exception e)
{
}
}