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)) {