Commit: 2be9313
Parent: 2edd64d

Browsing at commits

Mårten Åsberg committed on 2025-11-09 at 19:46
GitBrowser/Components/Pages/Commit.razor +6 -0
diff --git a/GitBrowser/Components/Pages/Commit.razor b/GitBrowser/Components/Pages/Commit.razor
index d81394a..d726c68 100644
@@ -57,6 +57,12 @@ else if (commit != null)
<pre>@commitBody</pre>
</div>
}
<div class="commit-actions">
<a href="/repo/tree/@commit.Sha" class="browse-button">
Browse files at this commit
</a>
</div>
</div>
</div>
}
GitBrowser/Components/Pages/Commit.razor.css +23 -0
diff --git a/GitBrowser/Components/Pages/Commit.razor.css b/GitBrowser/Components/Pages/Commit.razor.css
index 478da2b..f127a1e 100644
@@ -101,3 +101,26 @@ code {
white-space: pre-wrap;
word-wrap: break-word;
}
.commit-actions {
margin-top: 1.5rem;
padding-top: 1.5rem;
border-top: 1px solid #d0d7de;
}
.browse-button {
display: inline-flex;
align-items: center;
padding: 0.5rem 1rem;
background: #0969da;
color: white;
text-decoration: none;
border-radius: 6px;
font-weight: 500;
font-size: 0.875rem;
transition: background-color 0.2s;
}
.browse-button:hover {
background: #0860ca;
}
GitBrowser/Components/Pages/Repo.razor +35 -8
diff --git a/GitBrowser/Components/Pages/Repo.razor b/GitBrowser/Components/Pages/Repo.razor
index f18a9ce..65b5bc2 100644
@@ -167,19 +167,27 @@ else
repo = new Repository(repoPath);
// Determine which branch to use
currentBranch = Branch ?? repo.Head.FriendlyName;
// Determine which branch/commit to use
var branchOrCommit = Branch ?? repo.Head.FriendlyName;
currentPath = Path ?? "";
// Find the branch
var branch = repo.Branches[currentBranch];
if (branch == null)
// Try to find it as a branch first
var branch = repo.Branches[branchOrCommit];
if (branch != null)
{
SetNotFound();
return;
currentBranch = branch.FriendlyName;
currentCommit = branch.Tip;
}
else
{
// Try to look it up as a commit hash
currentCommit = repo.Lookup<LibGit2Sharp.Commit>(branchOrCommit);
if (currentCommit != null)
{
currentBranch = currentCommit.Sha.Substring(0, 7);
}
}
currentCommit = branch.Tip;
if (currentCommit == null)
{
SetNotFound();
@@ -306,6 +314,25 @@ else
return null;
}
private bool IsValidCommitHash(string value)
{
if (string.IsNullOrEmpty(value))
return false;
// Git commit hashes are 7-40 hex characters
if (value.Length < 7 || value.Length > 40)
return false;
// Check if all characters are valid hex digits
foreach (var c in value)
{
if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')))
return false;
}
return true;
}
private string GetRelativeTime(DateTimeOffset when)
{
var now = DateTimeOffset.Now;