Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(git): write-through commits fail commit_paths_skipped when git leaves a named path out (GST-2116)
garrytan0210ec172ea0
diff --git a/src/core/git/commit-push.ts b/src/core/git/commit-push.tsindex 7b53df34f1..e995392dd0 100644--- a/src/core/git/commit-push.ts+++ b/src/core/git/commit-push.ts@@ -490,7 +490,7 @@ function unindexedFiles(root: string, rel: string[], listed: string[]): string[]*/function skippedPathsError(root: string, skipped: SkippedPath[], result: CommitPushResult, managed?: ManagedFilesystemRoot): OperationError {const list = `${skipped.slice(0, 20).map(s => `${s.path} (${s.reason})`).join(', ')}${skipped.length > 20 ? ', ...' : ''}`;- const pushed = result.committed && !result.managed && !result.no_remote && result.outcome !== 'push_deferred';+ const pushed = !!result.committed && (result.outcome === 'pushed' || result.outcome === 'pushed_checkout_lagging');const rest = result.committed? `The other named paths were committed as ${result.committed.slice(0, 7)}${pushed ? ` and pushed to ${result.remote}/${result.branch}` : ', not pushed'}.`: 'Nothing was committed.';@@ -697,7 +697,8 @@ function settlePending(root: string): void {* doctor's `dirty_age` reports. It never commits without the lock: that races* other writers on the shared index. Paths must sit under `repo` (the source* root). No marker is set, so the post-commit hook publishes. Returns the new- * commit, or null when the paths had no change.+ * commit, or null when the paths had no change. A named path git left out fails+ * `commit_paths_skipped` after the rest is committed (GST-2116).*/export function commitPathsLocked(repo: string, rel: string[], message: string, opts: { lockWaitMs: number }): string | null {const root = checkoutRoot(repo);@@ -714,15 +715,19 @@ export function commitPathsLocked(repo: string, rel: string[], message: string,try {const pending = [...dirtyPaths(root, readPendingWriteThrough(root).map(e => e.path).filter(p => !paths.includes(p) && insideSourceRoots(p, roots)))];const scope = { roots, lockPath: lock.lockPath, markHeld: false };- let sha: string | null;+ let commit: ReturnType<typeof commitPaths>;try {- sha = commitPaths(root, [...paths, ...pending], pending.length ? `${message} (+${pending.length} pending write-through file(s))` : message, scope).sha;+ commit = commitPaths(root, [...paths, ...pending], pending.length ? `${message} (+${pending.length} pending write-through file(s))` : message, scope);} catch (e) {if (!pending.length) throw e;- sha = commitPaths(root, paths, message, scope).sha;+ commit = commitPaths(root, paths, message, scope);}settlePending(root);- return sha;+ if (commit.skipped.length) {+ const branch = git(root, ['symbolic-ref', '--quiet', '--short', 'HEAD']).stdout.trim();+ throw skippedPathsError(root, commit.skipped, { outcome: commit.sha ? 'committed_local' : 'nothing_to_commit', sha: commit.sha, committed: commit.sha, branch, remote: '', paths, integrated: 0, checkout: 'unchanged' });+ }+ return commit.sha;} catch (e) {if (PENDING_NOTED.has((e as { code?: string }).code ?? '')) notePending(root, paths);throw e;diff --git a/test/git-commit-push-skipped-paths-gst2116.test.ts b/test/git-commit-push-skipped-paths-gst2116.test.tsindex 956ef4d8d0..0b20dab52d 100644--- a/test/git-commit-push-skipped-paths-gst2116.test.ts+++ b/test/git-commit-push-skipped-paths-gst2116.test.ts@@ -14,6 +14,7 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSyimport { tmpdir } from 'node:os';import { join } from 'node:path';import { renderCommitPushHelper } from '../src/core/brain-repo-durability.ts';+import { commitPathsLocked } from '../src/core/git/commit-push.ts';import { recordManagedRoots } from '../src/core/persistence/root-registry.ts';import { runCli } from './helpers/cli-spawn.ts';import { withEnv } from './helpers/with-env.ts';@@ -272,3 +273,17 @@ test('helper without gbrain: a non-ASCII flagged path, a nested-repository fileexpect(remoteTip(f)).toBe(head(f));}, 90_000);+test('write-through: commitPathsLocked fails commit_paths_skipped for a nested-repository file instead of returning the commit', () => {+ const f = fixture('locked-nested', 'classic');+ writeFileSync(join(f.brain, 'people', 'bob-example.md'), page('Bob', 'Second version.'));+ const nested = nestedPage(f, 'carol-example.md');+ let failure: { code?: string; message?: string } | undefined;+ withEnv({ GBRAIN_HOME: f.home, ...identity }, () => {+ try { commitPathsLocked(f.brain, [join(f.brain, 'people', 'bob-example.md'), join(f.brain, nested)], 'gbrain: write-through', { lockWaitMs: 2_000 }); }+ catch (e) { failure = e as { code?: string; message?: string }; }+ });+ expect(failure?.code).toBe('commit_paths_skipped');+ expect(failure?.message).toContain(nested);+ expect(failure?.message).toContain('not pushed');+ expect(headBlob(f, 'people/bob-example.md')).toContain('Second version.');+}, 60_000);