From b018ba7864f9aa94d7088be350fa28a7838d6752 Mon Sep 17 00:00:00 2001 From: kicer Date: Fri, 13 Nov 2026 18:05:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20Git=20=E9=9D=A2=E6=9D=BF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=8A=8A=20origin/master=20=E6=A0=87=E5=9C=A8?= =?UTF-8?q?=E5=AE=83=E6=8C=87=E5=90=91=E7=9A=84=E6=8F=90=E4=BA=A4=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 列表只有本地历史,看不出哪条远端已经有了,也就判断不出本地领先几条。 ensureRepo 多返回 upstream(优先当前分支的 upstream,没配回退 origin/master), 列表渲染时给 id 相同的那条挂一枚 origin/master 徽章、行首加一条蓝竖线, 和 git log --decorate 一个意思。 --- app/server/git.js | 11 ++++++++++- app/server/public/css/style.css | 5 +++++ app/server/public/js/vcs.js | 7 +++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/server/git.js b/app/server/git.js index 2530e82..dbae993 100644 --- a/app/server/git.js +++ b/app/server/git.js @@ -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` 切开,键是文件路径。 diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index 9780a73..45caeed 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -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; } /* 「未提交的改动」入口:列表顶部单独一行,与提交行区分 */ diff --git a/app/server/public/js/vcs.js b/app/server/public/js/vcs.js index 3fe763a..efc0a1f 100644 --- a/app/server/public/js/vcs.js +++ b/app/server/public/js/vcs.js @@ -64,9 +64,12 @@ '
未提交的改动
' + '
' + st.worktree.files + ' 个文件有变动
'); } + const up = st.repo && st.repo.upstream; for (const c of st.commits) { - parts.push('
' + - '
' + esc(c.subject) + '
' + + const atUp = up && c.id === up.id; + parts.push('
' + + '
' + esc(c.subject) + + (atUp ? ' ' + esc(up.ref) + '' : '') + '
' + '
' + esc(c.author) + ' · ' + esc(fmtTime(c.time)) + ' · ' + esc(c.short) + '
'); } if (!st.commits.length && !(st.worktree && st.worktree.files)) {