@aiti-ai/aiti-git-ops 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/aiti-git-ops.test.mjs +18 -0
- package/git-engine.ts +7 -3
- package/index.ts +2 -2
- package/package.json +2 -2
package/aiti-git-ops.test.mjs
CHANGED
|
@@ -310,6 +310,24 @@ test("log 分页:--graph 无 --skip 语义下翻页完整(55 空提交)",
|
|
|
310
310
|
assert.equal(tail.body.lines.length, 0); // 越界空页不炸
|
|
311
311
|
});
|
|
312
312
|
|
|
313
|
+
test("log: decorate always on + ref filter (graph view branch filter, borrow plan 2.1)", async () => {
|
|
314
|
+
git(["checkout", "-b", "graphview-x"]);
|
|
315
|
+
git(["commit", "--allow-empty", "-m", "gvx-1"]);
|
|
316
|
+
git(["commit", "--allow-empty", "-m", "gvx-2"]);
|
|
317
|
+
const r = await call(["git", "log"], { cwd: repo, ref: "graphview-x" });
|
|
318
|
+
assert.equal(r.status, 200);
|
|
319
|
+
const tip = r.body.lines.find((l) => l.includes("gvx-2"));
|
|
320
|
+
assert.ok(/\(HEAD -> graphview-x\)/.test(tip)); // --decorate=short badge inline
|
|
321
|
+
assert.ok(r.body.lines.some((l) => l.includes("gvx-1")));
|
|
322
|
+
const back = await call(["git", "log"], { cwd: repo, ref: "main", cursor: 0 });
|
|
323
|
+
assert.equal(back.status, 200);
|
|
324
|
+
assert.ok(!back.body.lines.some((l) => l.includes("gvx-2"))); // main view excludes branch-only commits
|
|
325
|
+
assert.ok(back.body.lines.some((l) => l.includes("c55"))); // shared history still visible
|
|
326
|
+
const bad = await call(["git", "log"], { cwd: repo, ref: "-U executing" });
|
|
327
|
+
assert.equal(bad.status, 400); // same assertSafeRef gate as checkout
|
|
328
|
+
git(["checkout", "main"]);
|
|
329
|
+
});
|
|
330
|
+
|
|
313
331
|
test("审计 jsonl 已写入(state 分层路径)", async () => {
|
|
314
332
|
const auditPath = join(tmp, "ext", "config", "state", "aiti-git-ops", "git-ops.jsonl");
|
|
315
333
|
assert.equal(existsSync(auditPath), true);
|
package/git-engine.ts
CHANGED
|
@@ -295,18 +295,22 @@ export async function stashFiles(cwd: string, index: number): Promise<{ tracked:
|
|
|
295
295
|
/**
|
|
296
296
|
* 图谱分页。注意:`git log --graph` 与 `--skip` 不兼容(静默返回空,实测 git 2.48),
|
|
297
297
|
* 改为 --max-count=(skip+count+1) 后本地切片;是否还有下一页用 rev-list --count 判断。
|
|
298
|
+
* ref (optional, graph-view branch filter): defaults to HEAD; --decorate=short always on so the client can draw ref badges.
|
|
298
299
|
*/
|
|
299
|
-
export async function gitLog(cwd: string, cursor: number, count = 50): Promise<{ lines: string[]; nextCursor: number | null }> {
|
|
300
|
+
export async function gitLog(cwd: string, cursor: number, count = 50, ref?: string): Promise<{ lines: string[]; nextCursor: number | null }> {
|
|
300
301
|
const repo = await repoRoot(cwd);
|
|
302
|
+
const wanted = typeof ref === "string" ? ref.trim() : "";
|
|
303
|
+
const rev = wanted && wanted !== "HEAD" ? wanted : "HEAD";
|
|
304
|
+
if (rev !== "HEAD") assertSafeRef(rev, "ref");
|
|
301
305
|
const skip = Number.isInteger(cursor) && cursor > 0 ? cursor : 0;
|
|
302
|
-
const out = await run(repo, ["log", "--graph", "--oneline", "--date-order", `--max-count=${skip + count + 1}
|
|
306
|
+
const out = await run(repo, ["log", "--graph", "--oneline", "--date-order", "--decorate=short", `--max-count=${skip + count + 1}`, rev], 60_000);
|
|
303
307
|
const all = out.split("\n");
|
|
304
308
|
if (all[all.length - 1] === "") all.pop();
|
|
305
309
|
const lines = all.slice(skip, skip + count);
|
|
306
310
|
let nextCursor: number | null = null;
|
|
307
311
|
if (lines.length === count) {
|
|
308
312
|
try {
|
|
309
|
-
const total = Number((await run(repo, ["rev-list", "--count",
|
|
313
|
+
const total = Number((await run(repo, ["rev-list", "--count", rev], 30_000)).trim());
|
|
310
314
|
if (skip + count < total) nextCursor = skip + count;
|
|
311
315
|
} catch { /* 空仓库 */ }
|
|
312
316
|
}
|
package/index.ts
CHANGED
|
@@ -52,7 +52,7 @@ export default {
|
|
|
52
52
|
try {
|
|
53
53
|
ctx.services?.provide?.("aiti-git-ops.api", {
|
|
54
54
|
refs: (cwd: string) => engine.gitRefs(cwd),
|
|
55
|
-
log: (cwd: string, cursor: number) => engine.gitLog(cwd, cursor),
|
|
55
|
+
log: (cwd: string, cursor: number, ref?: string) => engine.gitLog(cwd, cursor, 50, ref),
|
|
56
56
|
checkout: (cwd: string, ref: string, mode?: string) => engine.gitCheckout(cwd, ref, mode),
|
|
57
57
|
branchCreate: (cwd: string, name: string, from?: string, checkout?: boolean) => engine.gitBranchCreate(cwd, name, from, checkout),
|
|
58
58
|
branchDelete: (cwd: string, name: string) => engine.gitBranchDelete(cwd, name),
|
|
@@ -103,7 +103,7 @@ export default {
|
|
|
103
103
|
try {
|
|
104
104
|
switch (p[1]) {
|
|
105
105
|
case "refs": return json({ ok: true, ...(await engine.gitRefs(cwd)) });
|
|
106
|
-
case "log": return json({ ok: true, ...(await engine.gitLog(cwd, body?.cursor ?? 0)) });
|
|
106
|
+
case "log": return json({ ok: true, ...(await engine.gitLog(cwd, body?.cursor ?? 0, 50, body?.ref)) });
|
|
107
107
|
case "checkout": return json(await engine.gitCheckout(cwd, body?.ref, body?.mode));
|
|
108
108
|
case "branch-create": return json(await engine.gitBranchCreate(cwd, body?.name, body?.from, body?.checkout !== false));
|
|
109
109
|
case "branch-delete": return json(await engine.gitBranchDelete(cwd, body?.name));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiti-ai/aiti-git-ops",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Whitelisted git write engine — checkout precheck / stash / plan breakpoints / audit / changed topic, consumed by folder and session-manager",
|
|
5
5
|
"soul": "一处写仓,处处安全。",
|
|
6
6
|
"aitiExtProtocol": "1.0",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@aiti-ai/ext-shared": "^0.1.12"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"contentHash": "
|
|
11
|
+
"contentHash": "af29f11dd3e18ac5",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git+https://github.com/aiti-ai/aiti-ai.git",
|