Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(git): commit-push still fails commit_paths_skipped when the push fails after a skipped path (GST-2116)

garrytan211e4c861527
diff --git a/src/commands/git.ts b/src/commands/git.ts
index 6a221b1472..15a14946a5 100644
--- a/src/commands/git.ts
+++ b/src/commands/git.ts
@@ -273,18 +273,20 @@ export async function runGit(args: string[]): Promise<number> {
return 0;
} catch (e) {
const code = (e as { code?: string }).code;
+ let failed = e as { code?: string | null; detail?: string | null };
if (code === 'commit_paths_skipped' || code === 'writer_coordinator_required') {
- // GST-2116: the other named paths may have been pushed before the run failed; the push log records that push.
+ // GST-2116: the other named paths may have been pushed before the run failed, or their push failed (`publish`); the push log records either.
try {
- const d = JSON.parse(String((e as { detail?: string }).detail ?? '{}')) as { pushed?: string; branch?: string };
+ const d = JSON.parse(String((e as { detail?: string }).detail ?? '{}')) as { pushed?: string; branch?: string; publish?: { code: string | null; detail: string | null } };
if (d.pushed && d.branch) appendPushLog('ok', d.branch, d.pushed);
+ if (d.publish) failed = d.publish;
} catch { /* best-effort */ }
}
- if (code === 'push_unconfirmed' || code === 'integrate_conflict' || code === 'commit_outside_source_root') {
+ if (failed.code === 'push_unconfirmed' || failed.code === 'integrate_conflict' || failed.code === 'commit_outside_source_root') {
try {
const bi = args.indexOf('--branch');
const branch = bi !== -1 && args[bi + 1] ? args[bi + 1].replace(/^refs\/heads\//, '') : currentBranchOf(args);
- appendPushLog(code === 'integrate_conflict' ? 'conflict' : 'local-only', branch, (e as { detail?: string }).detail ?? '');
+ appendPushLog(failed.code === 'integrate_conflict' ? 'conflict' : 'local-only', branch, failed.detail ?? '');
} catch { /* best-effort */ }
}
return writeCliError(e, 'git commit-push', { json });
diff --git a/src/core/git/commit-push.ts b/src/core/git/commit-push.ts
index e995392dd0..8a7db81455 100644
--- a/src/core/git/commit-push.ts
+++ b/src/core/git/commit-push.ts
@@ -488,13 +488,16 @@ function unindexedFiles(root: string, rel: string[], listed: string[]): string[]
* rest, so a write is never reported as saved when it is not. In a managed canonical worktree a skipped page is the
* owner's to save (`writer_coordinator_required`); anything else is `commit_paths_skipped`.
*/
-function skippedPathsError(root: string, skipped: SkippedPath[], result: CommitPushResult, managed?: ManagedFilesystemRoot): OperationError {
+function skippedPathsError(root: string, skipped: SkippedPath[], result: CommitPushResult, managed?: ManagedFilesystemRoot, publish?: unknown): OperationError {
const list = `${skipped.slice(0, 20).map(s => `${s.path} (${s.reason})`).join(', ')}${skipped.length > 20 ? ', ...' : ''}`;
const pushed = !!result.committed && (result.outcome === 'pushed' || result.outcome === 'pushed_checkout_lagging');
- const rest = result.committed
+ const done = 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.';
- const detail = JSON.stringify({ skipped, committed: result.committed, ...(pushed ? { pushed: result.sha } : {}), branch: result.branch });
+ const failed = publish as { code?: string; message?: string; detail?: string } | undefined;
+ const rest = `${done}${failed ? ` The push failed too (${failed.code ?? 'error'}): ${failed.message ?? String(publish)}` : ''}`;
+ const detail = JSON.stringify({ skipped, committed: result.committed, ...(pushed ? { pushed: result.sha } : {}), branch: result.branch,
+ ...(failed ? { publish: { code: failed.code ?? null, detail: failed.detail ?? null } } : {}) });
const docs = 'docs/guides/shared-checkout-git.md#outcomes';
const flagged = skipped.filter(s => s.reason !== 'not_staged');
// One update-index call per flag: given both, git clears only the first.
@@ -1338,15 +1341,18 @@ export function commitAndPush(opts: CommitPushOptions): CommitPushResult {
writeFileSync(requestPath, `${process.pid}\n`);
pub = acquireNativeLockSync(publishLockPath, { timeoutMs: 0 });
}
+ const unpublished: CommitPushResult = { outcome: 'committed_local', sha: null, committed, branch: ctx.branch, remote: ctx.remote, paths: rel, integrated: 0, checkout: 'unchanged' };
if (!pub) {
if (unattended) {
- const deferred: CommitPushResult = { outcome: 'push_deferred', sha: null, committed, branch: ctx.branch, remote: ctx.remote, paths: rel, integrated: 0, checkout: 'unchanged' };
+ const deferred: CommitPushResult = { ...unpublished, outcome: 'push_deferred' };
if (skipped.length) throw skippedPathsError(root, skipped, deferred);
return deferred;
}
- throw opError('push_unconfirmed', `${committed ? 'The commit is durable locally, but another' : 'Another'} publish held this checkout's push lock for ${Math.round(waitMs / 1000)}s.`,
+ const busy = opError('push_unconfirmed', `${committed ? 'The commit is durable locally, but another' : 'Another'} publish held this checkout's push lock for ${Math.round(waitMs / 1000)}s.`,
`The running publish was asked to push HEAD too once it finishes. Rerun gbrain git commit-push --push-only to confirm; never git pull --rebase in this checkout.`,
{ detail: committed ?? '', retryable: true });
+ if (skipped.length) throw skippedPathsError(root, skipped, unpublished, undefined, busy);
+ throw busy;
}
const cycle = (onlyWhenClean: boolean, start: string | null, resolutions?: Map<string, Resolution>, expectRemote?: string) => {
@@ -1371,6 +1377,9 @@ export function commitAndPush(opts: CommitPushOptions): CommitPushResult {
let first: ReturnType<typeof cycle>;
try {
first = cycle(unattended, committed, opts.resolutions, opts.expectRemote);
+ } catch (e) {
+ if (skipped.length) throw skippedPathsError(root, skipped, unpublished, undefined, e);
+ throw e;
} finally {
pub.release();
}
diff --git a/test/git-commit-push-skipped-paths-gst2116.test.ts b/test/git-commit-push-skipped-paths-gst2116.test.ts
index 0b20dab52d..1103655315 100644
--- a/test/git-commit-push-skipped-paths-gst2116.test.ts
+++ b/test/git-commit-push-skipped-paths-gst2116.test.ts
@@ -287,3 +287,22 @@ test('write-through: commitPathsLocked fails commit_paths_skipped for a nested-r
expect(failure?.message).toContain('not pushed');
expect(headBlob(f, 'people/bob-example.md')).toContain('Second version.');
}, 60_000);
+
+test('classic: a skipped path still fails commit_paths_skipped when the push fails, and the push log records the local-only commit', async () => {
+ const f = fixture('classic-skip-pushfail', 'classic');
+ writeFileSync(join(f.brain, 'people', 'bob-example.md'), page('Bob', 'Second version.'));
+ const nested = nestedPage(f, 'carol-example.md');
+ git(f.brain, 'remote', 'set-url', 'origin', join(dir, 'missing.git'));
+ const r = await commitPush(f, 'people/bob-example.md', nested);
+ expect(r.exitCode).not.toBe(0);
+ const e = envelope(r.stdout);
+ expect(e.code).toBe('commit_paths_skipped');
+ expect(e.message).toContain(nested);
+ expect(e.message).toContain('not pushed');
+ const detail = JSON.parse(e.detail!) as { committed: string; pushed?: string; publish?: { code: string } };
+ expect(detail.committed).toBe(head(f));
+ expect(detail.pushed).toBeUndefined();
+ expect(detail.publish?.code).toBe('push_unconfirmed');
+ expect(headBlob(f, 'people/bob-example.md')).toContain('Second version.');
+ expect(readFileSync(join(f.home, '.gbrain', 'brain-push.log'), 'utf8')).toContain('LOCAL-ONLY, NEEDS ATTENTION: main');
+}, 60_000);