Skip to content

Commit 42b4cbc

Browse files
committed
1 parent 579faaa commit 42b4cbc

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/main/java/org/scm4j/vcs/GitVCS.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -670,36 +670,29 @@ public List<VCSCommit> getCommitsRange(String branchName, String startRevision,
670670
}
671671
}
672672

673-
private RevCommit getHeadRevCommit (String branchName) {
673+
@Override
674+
public VCSCommit getHeadCommit (String branchName) {
674675
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy();
675676
Git git = getLocalGit(wc);
676677
Repository gitRepo = git.getRepository();
677678
RevWalk rw = new RevWalk(gitRepo)) {
678679

679-
String bn = getRealBranchName(branchName);
680-
681-
Ref ref = gitRepo.exactRef(REFS_REMOTES_ORIGIN + bn);
680+
checkout(git, gitRepo, null, null);
681+
682+
Ref ref = gitRepo.exactRef(REFS_REMOTES_ORIGIN + getRealBranchName(branchName));
682683
if (ref == null) {
683684
return null;
684685
}
685686
ObjectId commitId = ref.getObjectId();
686-
return rw.parseCommit( commitId );
687+
RevCommit revCommit = rw.parseCommit( commitId );
688+
return getVCSCommit(revCommit);
687689
} catch (GitAPIException e) {
688690
throw new EVCSException(e);
689691
} catch (Exception e) {
690692
throw new RuntimeException(e);
691693
}
692694
}
693695

694-
@Override
695-
public VCSCommit getHeadCommit(String branchName) {
696-
RevCommit branchHeadCommit = getHeadRevCommit(getRealBranchName(branchName));
697-
if (branchHeadCommit == null) {
698-
return null;
699-
}
700-
return getVCSCommit(branchHeadCommit);
701-
}
702-
703696
@Override
704697
public String toString() {
705698
return "GitVCS [url=" + repo.getRepoUrl() + "]";

0 commit comments

Comments
 (0)