diff --git a/src/main/java/be/seeseepuff/webgit/controller/RepoController.java b/src/main/java/be/seeseepuff/webgit/controller/RepoController.java index d759547..b456e2b 100644 --- a/src/main/java/be/seeseepuff/webgit/controller/RepoController.java +++ b/src/main/java/be/seeseepuff/webgit/controller/RepoController.java @@ -63,6 +63,7 @@ public class RepoController { model.addAttribute("name", name); model.addAttribute("commits", gitService.listCommits(name)); + model.addAttribute("headHash", gitService.getHeadCommitHash(name)); return "commits"; } diff --git a/src/main/java/be/seeseepuff/webgit/service/GitService.java b/src/main/java/be/seeseepuff/webgit/service/GitService.java index 5747c66..be2734a 100644 --- a/src/main/java/be/seeseepuff/webgit/service/GitService.java +++ b/src/main/java/be/seeseepuff/webgit/service/GitService.java @@ -133,7 +133,8 @@ public class GitService .call() .stream() .map(Ref::getName) - .map(ref -> ref.startsWith("refs/heads/") ? ref.substring("refs/heads/".length()) : ref) + .filter(ref -> ref.startsWith("refs/heads/")) + .map(ref -> ref.substring("refs/heads/".length())) .toList(); } } @@ -146,6 +147,15 @@ public class GitService } } + public String getHeadCommitHash(String name) throws IOException + { + try (Git git = openRepository(name)) + { + ObjectId head = git.getRepository().resolve("HEAD"); + return head != null ? head.getName() : null; + } + } + public void checkoutBranch(String name, String branch) throws IOException, GitAPIException { try (Git git = openRepository(name)) @@ -273,10 +283,15 @@ public class GitService Repository repo = git.getRepository(); try (PlotWalk plotWalk = new PlotWalk(repo)) { + // Walk from all branch tips so we see all commits + for (Ref ref : repo.getRefDatabase().getRefsByPrefix("refs/heads/")) + { + plotWalk.markStart(plotWalk.parseCommit(ref.getObjectId())); + } + // Also include HEAD in case of detached HEAD ObjectId head = repo.resolve("HEAD"); - if (head == null) - return List.of(); - plotWalk.markStart(plotWalk.parseCommit(head)); + if (head != null) + plotWalk.markStart(plotWalk.parseCommit(head)); PlotCommitList plotCommitList = new PlotCommitList<>(); plotCommitList.source(plotWalk); diff --git a/src/main/resources/templates/blob.html b/src/main/resources/templates/blob.html index d0d40e1..6ff9f13 100644 --- a/src/main/resources/templates/blob.html +++ b/src/main/resources/templates/blob.html @@ -7,9 +7,9 @@

file.txt

-< Back to tree -| < Back to commits +| +< Back to tree

diff --git a/src/main/resources/templates/commits.html b/src/main/resources/templates/commits.html index 5ff0168..9ae328f 100644 --- a/src/main/resources/templates/commits.html +++ b/src/main/resources/templates/commits.html @@ -25,7 +25,8 @@
Browse -
+(current) +