JGit은 모든 알려진 서브 모듈을 나열하는 SubmoduleStatusCommand
을 가지고 있습니다. 이 명령 은 베어 리지 (non-bare) 리포지토리에서만 작동합니다. 당신이 볼 수 있듯이
Git git = Git.open(new File("/path/to/repo/.git"));
Map<String,SubmoduleStatus> submodules = git.submoduleStatus().call();
SubmoduleStatus status = submodules.get("repository/core");
ObjectId headId = status.getHeadId();
는 명령은 SHA-1 HEAD의 커밋이 포함되어 각각의 SubmoduleStatus
과 함께 서브 모듈-이름의 맵을 반환합니다.
얼마 전 더 자세한 내용이 담긴 article about JGit's submodule API도 있습니다. 당신과 같이 저장소의 객체 데이터베이스에서 직접 서브 모듈의 HEAD의 ID를 읽을 것이다 베어 저장소에
는 :
try(RevWalk revWalk = new RevWalk(repository)) {
RevCommit headCommit = revWalk.parseCommit(repository.resolve(Constants.HEAD));
}
try(TreeWalk treeWalk = TreeWalk.forPath(repository, "repository/core", headCommit.getTree())) {
ObjectId blobId = treeWalk.getObjectId(0);
ObjectLoader objectLoader = repository.open(blobId, Constants.OBJ_BLOB);
try(InputStream inputStream = objectLoader.openStream()) {
// read contents from the input stream
}
}
, 무엇 유형 "자식"에있다 당신의 본보기와 어디서 얻을 수 있습니까? –
나는 NoWorkTreeException을 얻고있다 : 베어 리포 지 토리 (Bare Repository)는 베어 리포 지 토리 (unare repository)에서 실행 중이기 때문에 작업 트리도 인덱스도 없다. 해결 방법이 있습니까? –
힘내는 명령을 만드는 데 사용할 수있는 팩토리 클래스입니다 (네이티브 힘의 도자기 명령과 유사). Git 인스턴스는 생성 된 저장소에 바인딩된다. Git 인스턴스를 만드는 한 방법은 Git.open (File)을 사용하는 것입니다. 지금 확장 답변을 참조하십시오. –