I know the support for git submodules is limited in JGit, but still was wondering how can I achieve this:

git submodule foreach git checkout <branchName>

and similar commands using JGit.

Or is there any other better Java based API for Git?

有帮助吗?

解决方案

In JGit there is a SubmoduleWalk that might help with your problem. To run a checkout command on all submodules, you would write something along these lines:

try (SubmoduleWalk walk = SubmoduleWalk.forIndex(repository)) {
  while(walk.next()) {
    try (Repository submoduleRepository = walk.getRepository()) {
      Git.wrap(submoduleRepository).checkout().call();
    }
  }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top