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` 切开,键是文件路径。