feat(ui): 文件树新增 Git 面板(提交历史 / 提交详情 / 未提交改动)
原来想看仓库改了什么只能开终端敲 git,界面里没有入口。复用预览栏做二选一 (body.pv-mode-vcs):打开时占预览的位置,点文件自动切回预览,不再各占一块屏。 三个视图只用一个渲染器:列表 → 点提交进详情,顶部「未提交的改动」进工作区, 两者仅头部信息不同(有无 commit 元信息)。只读,不做 commit / checkout / pull。 不做任何自动刷新:只在打开面板、切视图、点刷新时请求,避免边干活边被打断。 后端 git.js 用 execFile 调 git,加 -c core.quotepath=false 保中文路径不被转义成 八进制;status 用 -z 输出,否则含空格的路径带引号、和 diff 里的裸路径对不上。 patch 按单文件 120KB / 合计 400KB 截断,未跟踪文件用 diff --no-index 现算。 不是仓库或没装 git 返回 HTTP 200 + reason,由界面给空状态。 镜像补装 git,apt 源照 executor/Dockerfile 换成腾讯云镜像(默认源在国内 update 会卡死)。
This commit is contained in:
@@ -9,6 +9,7 @@ const { listTaskFiles } = require('./sessions');
|
||||
const { resolveInTask } = require('../tools/executor');
|
||||
const downloadToken = require('../download-token');
|
||||
const log = require('../log');
|
||||
const git = require('../git');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
@@ -142,6 +143,32 @@ router.get('/:id/tree', function (req, res) {
|
||||
});
|
||||
});
|
||||
|
||||
// ---------- Git 面板(只读):提交列表 / 提交详情 ----------
|
||||
// rev=worktree 是「未提交的改动」,与提交详情返回同一副骨架(commit=null),前端共用一个渲染器。
|
||||
// 不是仓库 / 没装 git 不算错误:HTTP 200 + { ok:false, reason },由界面显示空状态。
|
||||
function gitDir(req) { return engine.taskDirOf(req.params.id); }
|
||||
|
||||
router.get('/:id/git/commits', async function (req, res) {
|
||||
const session = engine.getSession(req.params.id);
|
||||
if (!session) return res.status(404).json({ error: '会话不存在' });
|
||||
const limit = Math.min(Math.max(parseInt(req.query.limit, 10) || 30, 1), 100);
|
||||
const before = String(req.query.before || '');
|
||||
// before 只接受完整/短 hash:它会拼进 git 参数,绝不能是任意表达式
|
||||
const out = await git.query(gitDir(req), 'commits', {
|
||||
before: /^[0-9a-f]{7,40}$/i.test(before) ? before : '',
|
||||
limit,
|
||||
});
|
||||
res.json(out);
|
||||
});
|
||||
|
||||
router.get('/:id/git/commit/:rev', async function (req, res) {
|
||||
const session = engine.getSession(req.params.id);
|
||||
if (!session) return res.status(404).json({ error: '会话不存在' });
|
||||
const rev = String(req.params.rev || '');
|
||||
if (rev !== 'worktree' && !/^[0-9a-f]{4,40}$/i.test(rev)) return res.status(400).json({ error: '非法的提交编号' });
|
||||
res.json(await git.query(gitDir(req), 'commit', { rev }));
|
||||
});
|
||||
|
||||
router.get('/:id/files', function (req, res) {
|
||||
try {
|
||||
const session = engine.getSession(req.params.id);
|
||||
|
||||
Reference in New Issue
Block a user