Fix branch/commit view bugs
- Filter out non-branch refs (like HEAD) from branch list - Walk all branch tips in commit list so older checkouts still show newer commits - Show '(current)' instead of Checkout button for HEAD commit - Swap nav link order in blob view (commits first, then tree) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -63,6 +63,7 @@ public class RepoController
|
|||||||
{
|
{
|
||||||
model.addAttribute("name", name);
|
model.addAttribute("name", name);
|
||||||
model.addAttribute("commits", gitService.listCommits(name));
|
model.addAttribute("commits", gitService.listCommits(name));
|
||||||
|
model.addAttribute("headHash", gitService.getHeadCommitHash(name));
|
||||||
return "commits";
|
return "commits";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,8 @@ public class GitService
|
|||||||
.call()
|
.call()
|
||||||
.stream()
|
.stream()
|
||||||
.map(Ref::getName)
|
.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();
|
.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
|
public void checkoutBranch(String name, String branch) throws IOException, GitAPIException
|
||||||
{
|
{
|
||||||
try (Git git = openRepository(name))
|
try (Git git = openRepository(name))
|
||||||
@@ -273,9 +283,14 @@ public class GitService
|
|||||||
Repository repo = git.getRepository();
|
Repository repo = git.getRepository();
|
||||||
try (PlotWalk plotWalk = new PlotWalk(repo))
|
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");
|
ObjectId head = repo.resolve("HEAD");
|
||||||
if (head == null)
|
if (head != null)
|
||||||
return List.of();
|
|
||||||
plotWalk.markStart(plotWalk.parseCommit(head));
|
plotWalk.markStart(plotWalk.parseCommit(head));
|
||||||
|
|
||||||
PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<>();
|
PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<>();
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
<h2 th:text="${filePath}">file.txt</h2>
|
<h2 th:text="${filePath}">file.txt</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a th:href="@{/repo/{name}/tree/{hash}(name=${name}, hash=${hash})}">< Back to tree</a>
|
|
||||||
|
|
|
||||||
<a th:href="@{/repo/{name}/commits(name=${name})}">< Back to commits</a>
|
<a th:href="@{/repo/{name}/commits(name=${name})}">< Back to commits</a>
|
||||||
|
|
|
||||||
|
<a th:href="@{/repo/{name}/tree/{hash}(name=${name}, hash=${hash})}">< Back to tree</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<table border="0" cellpadding="4" cellspacing="0">
|
<table border="0" cellpadding="4" cellspacing="0">
|
||||||
|
|||||||
@@ -25,7 +25,8 @@
|
|||||||
<td th:text="${c.date}"></td>
|
<td th:text="${c.date}"></td>
|
||||||
<td><a th:href="@{/repo/{name}/tree/{hash}(name=${name}, hash=${c.hash})}">Browse</a></td>
|
<td><a th:href="@{/repo/{name}/tree/{hash}(name=${name}, hash=${c.hash})}">Browse</a></td>
|
||||||
<td>
|
<td>
|
||||||
<form method="post" th:action="@{/repo/{name}/checkout-commit(name=${name})}">
|
<span th:if="${c.hash == headHash}">(current)</span>
|
||||||
|
<form th:unless="${c.hash == headHash}" method="post" th:action="@{/repo/{name}/checkout-commit(name=${name})}">
|
||||||
<input type="hidden" name="hash" th:value="${c.hash}">
|
<input type="hidden" name="hash" th:value="${c.hash}">
|
||||||
<input type="submit" value="Checkout">
|
<input type="submit" value="Checkout">
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user