feat(ui): Git 面板列表把 origin/master 标在它指向的提交上

列表只有本地历史,看不出哪条远端已经有了,也就判断不出本地领先几条。

ensureRepo 多返回 upstream(优先当前分支的 upstream,没配回退 origin/master),
列表渲染时给 id 相同的那条挂一枚 origin/master 徽章、行首加一条蓝竖线,
和 git log --decorate 一个意思。
This commit is contained in:
2026-11-13 18:05:54 +08:00
parent c07fc3be58
commit b018ba7864
3 changed files with 20 additions and 3 deletions
+10 -1
View File
@@ -55,7 +55,16 @@ async function ensureRepo(dir) {
const m = /^(\S+)\s+(\S+)\s+\(fetch\)/.exec(first);
if (m) remote = { name: m[1], url: m[2].replace(/\/\/[^/@]+@/, '//***@') };
} catch (_) { /* 没配 remote */ }
return { root, branch: branch || (head ? 'detached' : ''), head, remote };
// upstream:列表要把 origin/master 标在它指向的那条提交上,一眼看出本地领先几条。
// 优先当前分支的 upstream,没配就回退 origin/master。
let upstream = null;
try {
const ref = (await run(root, ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}'])).trim();
if (ref) upstream = { ref, id: (await run(root, ['rev-parse', ref])).trim() };
} catch (_) {
try { upstream = { ref: 'origin/master', id: (await run(root, ['rev-parse', 'origin/master'])).trim() }; } catch (__) { upstream = null; }
}
return { root, branch: branch || (head ? 'detached' : ''), head, remote, upstream };
}
// 把一个整段 diff 按 `diff --git` 切开,键是文件路径。
+5
View File
@@ -1931,6 +1931,11 @@ body.pv-max .pv-code { max-width: none; padding-left: 16px; padding-right: 16px;
.vcs-item { padding: 10px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.vcs-item:hover { background: var(--surface); }
.vcs-item .t { font-size: 13.5px; font-weight: 600; color: var(--ink); word-break: break-word; line-height: 1.45; }
/* 远端分支(origin/master)指向的那条提交:标题后挂一枚小标签,一眼看出本地领先几条 */
.vcs-up { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 999px;
font: 600 10.5px/17px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
color: var(--fg-0550ae); background: var(--bg-dbeafe); vertical-align: 1px; }
.vcs-item.at-up { box-shadow: inset 3px 0 0 var(--active); }
.vcs-item .m { margin-top: 3px; font-size: 12px; color: var(--gray); }
.vcs-item .m code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
/* 「未提交的改动」入口:列表顶部单独一行,与提交行区分 */
+5 -2
View File
@@ -64,9 +64,12 @@
'<div class="t">未提交的改动</div>' +
'<div class="m">' + st.worktree.files + ' 个文件有变动</div></div>');
}
const up = st.repo && st.repo.upstream;
for (const c of st.commits) {
parts.push('<div class="vcs-item" data-act="commit" data-id="' + esc(c.id) + '">' +
'<div class="t">' + esc(c.subject) + '</div>' +
const atUp = up && c.id === up.id;
parts.push('<div class="vcs-item' + (atUp ? ' at-up' : '') + '" data-act="commit" data-id="' + esc(c.id) + '">' +
'<div class="t">' + esc(c.subject) +
(atUp ? ' <span class="vcs-up" title="远端 ' + esc(up.ref) + ' 指向这里">' + esc(up.ref) + '</span>' : '') + '</div>' +
'<div class="m">' + esc(c.author) + ' · ' + esc(fmtTime(c.time)) + ' · ' + esc(c.short) + '</div></div>');
}
if (!st.commits.length && !(st.worktree && st.worktree.files)) {