JGit and finding the Head

后端 未结 4 1924
名媛妹妹
名媛妹妹 2021-01-01 10:23

I\'m trying to get my hands on the HEAD commit with JGit:

val builder = new FileRepositoryBuilder()
val repo = builder.setGitDir(new File(\"/www/test-repo\")         


        
4条回答
  •  死守一世寂寞
    2021-01-01 11:13

    For me (using 4.5.0.201609210915-r) the solution was to use just RepositoryBuilder instead of FileRepositoryBuilder. Until I made this change all methods were returning null.

    rb = new org.eclipse.jgit.lib.RepositoryBuilder()
        .readEnvironment()
        .findGitDir()
        .build();
    
    headRef = rb.getRef(rb.getFullBranch());
    headHash = headRef.getObjectId().name();
    

提交回复
热议问题