Self-hosted git - made by qwen 3.8 27b
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
@page "/{Owner}/{Repo}/commit/{Sha}"
@inherits RepoPageBase
@inject RefService Refs
@inject ForgeDb Db
@if (Repository is not null && _commit is not null && _diff is not null)
{
<PageTitle>@_commit.Subject · @_commit.ShortSha</PageTitle>
<HighlightAssets/>
<RepoHeader Repository="Repository" Active="commits" IsOwner="IsOwner"/>
@if (_error is not null)
{
<div class="alert error">
<p>@_error</p>
@if (_conflicts.Count > 0)
{
<ul>
@foreach (var file in _conflicts)
{
<li><code>@file</code></li>
}
</ul>
}
</div>
}
<section class="card commit-detail">
<h2 class="commit-title">@(_commit.Subject.Length == 0 ? T["(no message)"] : _commit.Subject)</h2>
@if (_commit.Body.Length > 0)
{
<pre class="commit-body">@_commit.Body</pre>
}
<dl class="meta">
<dt>@T["Author"]</dt>
<dd><Avatar Name="@_commit.AuthorName"/> @_commit.AuthorName <@_commit.AuthorEmail> · <TimeAgo Value="_commit.AuthorDate"/></dd>
@if (_commit.CommitterName != _commit.AuthorName || _commit.CommitterEmail != _commit.AuthorEmail)
{
<dt>@T["Committer"]</dt>
<dd>@_commit.CommitterName <@_commit.CommitterEmail> · <TimeAgo Value="_commit.CommitDate"/></dd>
}
<dt>@T["Commit"]</dt>
<dd>
<code>@_commit.Sha</code>
<button type="button" class="icon-button inline js-only" data-copy="@_commit.Sha"
title="@T["Copy the full SHA"]" aria-label="@T["Copy the full SHA"]">
<Icon Name="copy" Size="14"/>
</button>
</dd>
<dt>@(_commit.Parents.Count == 1 ? T["Parent"] : T["Parents"])</dt>
<dd>
@if (_commit.Parents.Count == 0)
{
<span class="muted">@T["none (first commit)"]</span>
}
@foreach (var parent in _commit.Parents)
{
<a class="sha" href="@Urls.Commit(Repository, parent)">@(parent[..8])</a>
}
</dd>
</dl>
<p><a class="button" href="@Urls.Tree(Repository, _commit.Sha)"><Icon Name="code"/> @T["Browse files at this commit"]</a></p>
@* Reverting and cherry-picking need exactly one parent to know what "this commit's change" is. *@
@if (IsOwner && _commit.Parents.Count == 1 && _branches.Count > 0)
{
<form method="post" @formname="apply-commit" @onsubmit="ApplyAsync" class="toolbar apply-form">
<AntiforgeryToken/>
<label>
<span class="muted">@T["Apply to branch"]</span>
<select name="Branch">
@foreach (var branch in _branches)
{
<option value="@branch" selected="@(branch == Repository.DefaultBranch)">@branch</option>
}
</select>
</label>
<button type="submit" name="Action" value="revert" class="button">@T["Revert"]</button>
<button type="submit" name="Action" value="pick" class="button">@T["Cherry-pick"]</button>
</form>
}
</section>
<h3>
@T.Plural(_diff.Stats.Count, "{0} changed file", "{0} changed files"):
<span class="added">+@_diff.Stats.Sum(s => s.Added ?? 0)</span>
<span class="deleted">−@_diff.Stats.Sum(s => s.Deleted ?? 0)</span>
</h3>
@if (_commit.Parents.Count > 1)
{
<p class="muted">@T["Merge commit: changes are shown against the first parent."]</p>
}
<DiffOptions Path="@Urls.Commit(Repository, _commit.Sha)" Split="Split" IgnoreWhitespace="IgnoreWhitespace"/>
<DiffView Diff="_diff.Patch" Split="Split" Repository="Repository" HeadSha="@_commit.Sha"/>
}
@code {
[Parameter]
public string Sha { get; set; } = "";
[SupplyParameterFromQuery(Name = "view")]
private string? View { get; set; }
[SupplyParameterFromQuery(Name = "w")]
private string? Whitespace { get; set; }
[SupplyParameterFromForm(FormName = "apply-commit")]
private string? Branch { get; set; }
[SupplyParameterFromForm(FormName = "apply-commit")]
private string? Action { get; set; }
private CommitInfo? _commit;
private CommitDiff? _diff;
private List<string> _branches = [];
private string? _error;
private IReadOnlyList<string> _conflicts = [];
private bool Split => View == "split";
private bool IgnoreWhitespace => Whitespace == "1";
protected override async Task OnInitializedAsync()
{
if (!await LoadRepoAsync())
{
return;
}
// ResolveCommitAsync accepts hex only, so nothing else from the URL reaches git.
var sha = await Git.ResolveCommitAsync(RepoPath, Sha);
_commit = sha is null ? null : await Git.GetCommitAsync(RepoPath, sha);
if (_commit is null)
{
NotFound();
return;
}
_diff = await Git.GetDiffAsync(RepoPath, _commit.Sha, IgnoreWhitespace);
if (IsOwner)
{
_branches = (await Git.ListRefsAsync(RepoPath)).Where(r => r.Kind == RefKind.Branch).Select(r => r.Name).ToList();
}
}
private async Task ApplyAsync()
{
if (Repository is null || _commit is null || !IsOwner || Action is not ("revert" or "pick"))
{
return;
}
var user = await Db.Users.FindAsync(Me.UserId);
if (user is null)
{
return;
}
var revert = Action == "revert";
var result = await Refs.ApplyCommitAsync(Repository, Refs.IdentityFor(user), Branch ?? "", _commit.Sha, revert);
if (!result.Ok)
{
_error = T[result.Error!];
_conflicts = result.Conflicts ?? [];
return;
}
Redirect(Urls.Commit(Repository, result.Sha!));
}
}