Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes

garrytand21ed88f86f9
diff --git a/src/commands/git.ts b/src/commands/git.ts
index 39e7c58c2b..e58e7d4bb5 100644
--- a/src/commands/git.ts
+++ b/src/commands/git.ts
@@ -243,8 +243,8 @@ export async function runGit(args: string[]): Promise<number> {
return 0;
}
if (result.managed) {
- const upstream = `${result.remote}/${result.branch}`;
- const state = !result.remote ? `${result.branch} has no upstream`
+ const upstream = result.upstream;
+ const state = !upstream ? `${result.branch} has no upstream`
: result.unpublished === 0 ? `${result.branch} is on ${upstream} as last fetched`
: `${result.unpublished ?? 'an unknown number of'} commit(s) on ${result.branch} ${result.unpublished === null ? 'may not be' : 'are not'} on ${upstream} as last fetched; a managed checkout publishes through its owner (gbrain git commit-push --push-only --keep-checkout --path ${repo} publishes them)`;
emit(json, { ...result, repo }, `${result.committed ? `committed ${result.committed.slice(0, 7)} on ${result.branch}` : 'nothing to commit'}; not pushed: ${state}`);
diff --git a/src/core/git/commit-push.ts b/src/core/git/commit-push.ts
index 6eb941bb4b..8c80602780 100644
--- a/src/core/git/commit-push.ts
+++ b/src/core/git/commit-push.ts
@@ -84,6 +84,8 @@ export interface CommitPushResult {
managed?: true;
/** Managed only: commits on the branch its upstream lacks as last fetched; null when no fetched upstream can be read. */
unpublished?: number | null;
+ /** Managed only: the branch's configured upstream (`origin/main`); null when it names none. */
+ upstream?: string | null;
}
export interface PullResult {
@@ -1101,7 +1103,8 @@ function commitManagedPaths(root: string, opts: CommitPushOptions, managed: Mana
}
const result = commitPathsOnly(root, opts, where, configuredSourceRoots(root), 'Leave the checkout to its owner; gbrain sources writer status names its state.');
const counted = git(root, ['rev-list', '--count', '@{upstream}..HEAD']);
- return { ...result, managed: true, unpublished: counted.code === 0 ? Number(counted.stdout.trim()) : null };
+ const upstream = git(root, ['for-each-ref', '--format=%(upstream:short)', `refs/heads/${result.branch}`]).stdout.trim();
+ return { ...result, managed: true, unpublished: counted.code === 0 ? Number(counted.stdout.trim()) : null, upstream: upstream || null };
}
/** A checkout with no Git remote at all: no remote is configured and the branch names none (a named but missing remote is refused by resolveCtx). A git command that fails is not proof of "no remote". */
diff --git a/test/git-commit-push-managed-unpublished.test.ts b/test/git-commit-push-managed-unpublished.test.ts
index 4bd6c16730..ea4eb6c799 100644
--- a/test/git-commit-push-managed-unpublished.test.ts
+++ b/test/git-commit-push-managed-unpublished.test.ts
@@ -92,5 +92,29 @@ test('a branch with no upstream reports no upstream instead of a count', async (
writeFileSync(join(f.brain, 'people', 'dave-example.md'), page('Dave', 'New page.'));
const result = await commitPush(f, true, 'people/dave-example.md');
expect(result.exitCode).toBe(0);
- expect(JSON.parse(result.stdout)).toMatchObject({ outcome: 'committed_local', managed: true, unpublished: null });
+ expect(JSON.parse(result.stdout)).toMatchObject({ outcome: 'committed_local', managed: true, unpublished: null, upstream: null });
+ const text = await commitPush(f, false, 'people/dave-example.md');
+ expect(text.stdout).toContain('nothing to commit; not pushed: main has no upstream');
+ expect(text.stdout).not.toContain('origin/main');
+}, 60_000);
+
+test('an upstream whose fetched ref cannot be read reports an unknown count, never a number', async () => {
+ const f = fixture('unread');
+ git(f.brain, 'update-ref', '-d', 'refs/remotes/origin/main');
+ const result = await commitPush(f, true, 'people/alice-example.md');
+ expect(result.exitCode).toBe(0);
+ expect(JSON.parse(result.stdout)).toMatchObject({ outcome: 'nothing_to_commit', managed: true, unpublished: null, upstream: 'origin/main' });
+ const text = await commitPush(f, false, 'people/alice-example.md');
+ expect(text.stdout).toContain('nothing to commit; not pushed: an unknown number of commit(s) on main may not be on origin/main as last fetched');
+ expect(pushLog(f)).toBe('');
+}, 60_000);
+
+test('the message names the upstream the count used when it differs from the branch name', async () => {
+ const f = fixture('renamed');
+ git(f.brain, 'push', '-q', 'origin', 'main:trunk');
+ git(f.brain, 'fetch', '-q', 'origin');
+ git(f.brain, 'branch', '-q', '--set-upstream-to', 'origin/trunk');
+ const insync = await commitPush(f, false, 'people/alice-example.md');
+ expect(insync.exitCode).toBe(0);
+ expect(insync.stdout).toContain('nothing to commit; not pushed: main is on origin/trunk as last fetched');
}, 60_000);