Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(git): commit-push commits locally in a checkout with no Git remote (GBRA-133)

garrytan0d3882fca6d2
diff --git a/docs/guides/shared-checkout-git.md b/docs/guides/shared-checkout-git.md
index c3c79a738c..8c91919548 100644
--- a/docs/guides/shared-checkout-git.md
+++ b/docs/guides/shared-checkout-git.md
@@ -130,6 +130,16 @@ fetches, merges, pushes or moves the checkout, and refuses `--pending`,
publish. `--push-only` without `--keep-checkout` is still refused with
`writer_coordinator_required`.
+A checkout with no Git remote at all (`git remote` prints nothing and the
+branch names none) has nothing to publish to: `gbrain git commit-push -m "<msg>" -- <paths>`
+commits only the named paths under the commit lock and reports
+`committed_local` with `no_remote: true`, saying nothing was pushed.
+`--push-only`, `--pending`, `--branch`, `--resolve`/`--expect-remote` and
+`--require-clean` are refused there (`commit_paths_invalid`). Add a remote and
+set the branch upstream, then `gbrain git commit-push --push-only` publishes the
+local commits. A branch that names a remote which does not exist still refuses
+(`git_unavailable`).
+
The one form a managed worktree accepts is `--push-only --keep-checkout`. It
publishes the commits already on the branch, merging a moved remote in memory,
but never moves the checkout and skips its pre-push hook, so
@@ -155,7 +165,8 @@ Follow the error's `fix.next` as the
| --- | --- | --- |
| `pushed` | 0 | Done. Report the commit; a hosted link to the file works now. |
| `push_deferred` | 0 | Only with `--require-clean` (the post-commit hook): another push was running in this checkout and was asked to publish HEAD too when it finishes. Nothing to do. |
-| `nothing_to_commit` | 0 | The paths had no change. Any earlier local commit on the branch was still pushed, so nothing is waiting. |
+| `nothing_to_commit` | 0 | The paths had no change. Any earlier local commit on the branch was still pushed, so nothing is waiting (with `no_remote: true`, nothing is pushed). |
+| `committed_local` | 0 | A managed canonical worktree, or a checkout with no Git remote (`no_remote: true`): the paths were committed locally and nothing was pushed. Report the commit; it reaches a remote on the owner's next publish, or after a remote is added and `--push-only` runs. |
| `pushed_checkout_lagging` | 0 | The push landed but this checkout was not advanced; a `[gbrain notice]` names the files that blocked it. Change nothing: the next commit-push or `--pull` catches the checkout up. Never stash or reset to "fix" it. |
| `commit_lock_busy` | 1 | Another writer held the lock for the whole wait; nothing was committed. Retry once. If it is still busy, tell the user which checkout and lock path the message names and stop. |
| `commit_paths_invalid` | 1 | No paths, a path outside the checkout, the checkout root itself, or a path git would not stage. Name the explicit files you wrote and rerun. |
@@ -168,7 +179,7 @@ Follow the error's `fix.next` as the
| `integrate_conflict` | 1 | Local and remote commits changed the same file; nothing was merged and the checkout is unchanged. Stop, relay the question to the user, then [resolve](#conflicts). |
| `push_unconfirmed` | 4 | The commit is durable locally but no push destination confirmed it (network, credentials, branch protection, a remote that kept moving, or another push that held the push lock for the whole wait). Fix what the message names, then run `gbrain git commit-push --push-only`. Never force-push. |
| `writer_coordinator_required` | 1 | This is a managed worktree. Stop using git for pages; save them through `put_page` and the other gbrain write tools. |
-| `git_unavailable` | 1 | A git command failed, often a missing `user.name`/`user.email` or a refusing pre-commit hook. Read the message, fix that, rerun. When the branch has no usable remote at all, the run stops before committing: add the remote, or commit locally with `git add <paths> && git commit -m "<msg>" -- <paths>`. |
+| `git_unavailable` | 1 | A git command failed, often a missing `user.name`/`user.email` or a refusing pre-commit hook. Read the message, fix that, rerun. When the branch names a remote that does not exist (a typo or a broken clone), the run stops before committing: fix the name or add the remote, then rerun. A checkout with no remote at all commits locally instead (`committed_local`). |
`--pull` reports `up_to_date`, `advanced`, `ahead` (local commits not yet
pushed; run `--push-only`), `skipped_dirty` (only with `--require-clean`) or
diff --git a/src/commands/git.ts b/src/commands/git.ts
index f86bb3bc13..25426ea478 100644
--- a/src/commands/git.ts
+++ b/src/commands/git.ts
@@ -35,6 +35,8 @@ rebase/stash/reset of the working tree, remote commits merged in memory, and the
checkout advanced fast-forward only. In a managed canonical worktree it only
commits the named paths (committed_local): no fetch, merge, push or checkout
move; the owner's next Git publish, or --push-only --keep-checkout, pushes it.
+In a checkout with no Git remote it also only commits the named paths
+(committed_local, no_remote); the publishing modes are refused there.
Flags:
--path <dir> Checkout to act on (default: the checkout containing the cwd).
@@ -186,6 +188,11 @@ export async function runGit(args: string[]): Promise<number> {
emit(json, { ...result, repo }, `push deferred: another push is running in ${repo} and will publish HEAD too`);
return 0;
}
+ if (result.no_remote) {
+ emit(json, { ...result, repo }, result.committed ? `committed ${result.committed.slice(0, 7)} on ${result.branch}; not pushed: ${repo} has no Git remote (add one with git remote add origin <url>, then gbrain git commit-push --push-only)`
+ : `nothing to commit; not pushed: ${repo} has no Git remote`);
+ return 0;
+ }
if (result.outcome === 'committed_local') {
emit(json, { ...result, repo }, `committed ${result.sha!.slice(0, 7)} on ${result.branch}; not pushed: this is a managed checkout, so the owner's next Git publish pushes it (or gbrain git commit-push --push-only --keep-checkout)`);
return 0;
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 2acfb123ac..348646d11d 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -1237,7 +1237,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.433.0', text: 'Hermes transcript import keeps the answers a user gave in a `clarify` form (answered responses of a submitted form, or the answers a timed-out form had already locked) as user turns, each after its question as the assistant\'s turn. A Hermes session imported before re-renders on its next import scan when it holds such answers, which can run fact extraction for that page again (#7396).' },
{ since: '0.60.433.0', text: 'Fact subject inference links more facts and fewer wrong ones: a currency code next to an amount (`CHF 80`) and a record label opening a sentence (`Invoice ...`, `Work session ...`) no longer block a fact that names one person or company, and an entity introduced only as an example (`including X notes`, `for example, X`) is never chosen as the subject. A page named like the code or label still competes. A sentence that opens with `For example, X ...` no longer takes X as its subject (#7405).' },
{ since: '0.60.433.0', text: '`gbrain think` gives reasoning models from gpt-5 on 16,000 output tokens behind any provider or router prefix, as it already did for gpt-5 and the o-series on their own provider; gpt-6 ids get it too. Before, those got 4,000 and long answers came back truncated (`LLM_OUTPUT_TRUNCATED`). Providers bill the tokens used, not the cap (#7421).' },
- { since: 'TBD', text: '`gbrain git commit-push` takes `-m` more than once, like `git commit`: each `-m` is a new paragraph of the message (a second `-m` carries a trailer). With `--path <dir>` below the checkout top, the paths after `--` are now relative to `<dir>` (like `git -C`), as its help said; they used to be read relative to the checkout top. The commit step that `gbrain repair frontmatter`, `gbrain repair content`, `gbrain repair file-drift` and the legacy fence repair (`gbrain sources status`, doctor `fence_integrity`) print for a legacy source is now `gbrain git commit-push --path <root> -m <subject> [-m <trailer>] -- <paths>`, which takes the writer lock, commits only those paths, merges remote commits and pushes, instead of a bare `git add` plus `git commit` (the frontmatter step named no paths on its commit, so it also committed anything else staged). A checkout with no remote refuses it (`git_unavailable`) and keeps the files uncommitted.' },
+ { since: 'TBD', text: '`gbrain git commit-push` takes `-m` more than once, like `git commit`: each `-m` is a new paragraph of the message (a second `-m` carries a trailer). With `--path <dir>` below the checkout top, the paths after `--` are now relative to `<dir>` (like `git -C`), as its help said; they used to be read relative to the checkout top. The commit step that `gbrain repair frontmatter`, `gbrain repair content`, `gbrain repair file-drift` and the legacy fence repair (`gbrain sources status`, doctor `fence_integrity`) print for a legacy source is now `gbrain git commit-push --path <root> -m <subject> [-m <trailer>] -- <paths>`, which takes the writer lock, commits only those paths, merges remote commits and pushes, instead of a bare `git add` plus `git commit` (the frontmatter step named no paths on its commit, so it also committed anything else staged). In a checkout with no Git remote at all (none configured and the branch names none), `gbrain git commit-push -m <msg> -- <paths>` now commits the named paths locally under the commit lock (outcome `committed_local` with `no_remote: true`, exit 0) and says nothing was pushed; it used to refuse `git_unavailable` and commit nothing. `--push-only`, `--pending`, `--branch`, `--resolve`/`--expect-remote` and `--require-clean` are refused there (`commit_paths_invalid`), and a branch that names a missing remote still refuses `git_unavailable`.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/git/commit-push.ts b/src/core/git/commit-push.ts
index eda1bade0e..a8daed1377 100644
--- a/src/core/git/commit-push.ts
+++ b/src/core/git/commit-push.ts
@@ -58,7 +58,7 @@ export type CheckoutState = 'advanced' | 'unchanged' | 'lagging';
export interface CommitPushResult {
/**
* `push_deferred`: an unattended publish found another publish running and left it a request to publish HEAD too.
- * `committed_local`: a managed canonical worktree, where commit-push only commits the named paths and never pushes.
+ * `committed_local`: a managed canonical worktree, or a checkout with no Git remote (`no_remote`), where commit-push only commits the named paths and never pushes.
*/
outcome: 'pushed' | 'nothing_to_commit' | 'pushed_checkout_lagging' | 'push_deferred' | 'committed_local';
/** The commit now on the remote branch (the caller's commit or the merge built over it). */
@@ -75,6 +75,8 @@ export interface CommitPushResult {
lagging_reason?: string;
/** Opt-in quarantine (git config gbrain.quarantine): the local versions of conflicting files, parked under a ref; the remote's version was published. */
quarantined?: QuarantineEntry;
+ /** The checkout has no Git remote: the paths were committed locally (or were already committed) and nothing was pushed. */
+ no_remote?: true;
}
export interface PullResult {
@@ -1013,17 +1015,41 @@ function commitManagedPaths(root: string, opts: CommitPushOptions, managed: Mana
throw opError('commit_paths_invalid', `${where}: commit-push there only commits the paths you name.`,
`Run gbrain git commit-push with only -m and the page paths after --; gbrain sources refresh${managed.sourceId ? ` ${managed.sourceId}` : ''} brings remote commits in.`);
}
+ return commitPathsOnly(root, opts, where, configuredSourceRoots(root), 'Leave the checkout to its owner; gbrain sources writer status names its state.');
+}
+
+/** 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". */
+function hasNoRemote(root: string): boolean {
+ const branch = git(root, ['symbolic-ref', '--quiet', '--short', 'HEAD']);
+ if (branch.code !== 0 || git(root, ['rev-parse', '--verify', '--quiet', 'HEAD']).code !== 0) return false;
+ const remotes = git(root, ['remote']);
+ if (remotes.code !== 0 || remotes.stdout.trim()) return false;
+ return git(root, ['config', '--get', `branch.${branch.stdout.trim()}.remote`]).code === 1;
+}
+
+/** GBRA-133: with no remote there is nothing to publish to, so commit-push only commits the named paths, like a managed worktree. */
+function commitRemotelessPaths(root: string, opts: CommitPushOptions): CommitPushResult {
+ const where = `${root} has no Git remote, so there is nothing to publish to`;
+ if (opts.pushOnly || opts.pending || opts.branch || opts.resolutions || opts.expectRemote || opts.advanceOnlyWhenClean) {
+ throw opError('commit_paths_invalid', `${where}; commit-push there only commits the paths you name.`,
+ 'Run gbrain git commit-push -m <msg> -- <paths> to commit them locally, or add a remote (git remote add origin <url>) and set the branch upstream to publish.');
+ }
+ return { ...commitPathsOnly(root, opts, where, opts.allowOutsideSourceRoot ? [''] : configuredSourceRoots(root), 'Check out a branch (git switch <branch>), then rerun.'), no_remote: true };
+}
+
+/** Commit only the named paths under the commit lock and nothing more: no fetch, merge, push or checkout move. */
+function commitPathsOnly(root: string, opts: CommitPushOptions, where: string, roots: string[], detachedFix: string): CommitPushResult {
if (!opts.message?.trim()) throw opError('commit_paths_invalid', 'A commit message is required.', 'Pass the commit message with -m.');
const rel = scopePaths(root, opts.paths ?? [], opts.cwd ?? process.cwd());
if (!rel.length) throw opError('commit_paths_invalid', `${where}: name the paths to commit.`, 'Pass -- <paths> after the message.');
const branch = git(root, ['symbolic-ref', '--quiet', '--short', 'HEAD']).stdout.trim();
- if (!branch) throw opError('git_detached_head', `${root} is on a detached HEAD, so there is no branch to commit to.`, 'Leave the checkout to its owner; gbrain sources writer status names its state.');
+ if (!branch) throw opError('git_detached_head', `${root} is on a detached HEAD, so there is no branch to commit to.`, detachedFix);
assertNoOperationInProgress(root);
const lock = acquireCommitLock(root, opts.lockWaitMs);
let committed: string | null;
try {
assertNoOperationInProgress(root);
- committed = commitPaths(root, rel, opts.message.trim(), { roots: configuredSourceRoots(root), lockPath: lock.lockPath, markHeld: true });
+ committed = commitPaths(root, rel, opts.message.trim(), { roots, lockPath: lock.lockPath, markHeld: true });
} finally {
lock.release();
}
@@ -1037,6 +1063,7 @@ export function commitAndPush(opts: CommitPushOptions): CommitPushResult {
const managed = opts.keepCheckout || opts.pushOnly ? null : managedFilesystemRootFor(root);
if (managed && !hasFilesystemPublication(root)) return commitManagedPaths(root, opts, managed);
if (!opts.keepCheckout) assertManagedFilesystemWrite(root);
+ if (hasNoRemote(root)) return commitRemotelessPaths(root, opts);
const cwd = opts.cwd ?? process.cwd();
const roots = configuredSourceRoots(root);
const rel = opts.pushOnly ? [] : opts.pending
diff --git a/test/git-commit-push-6530.serial.test.ts b/test/git-commit-push-6530.serial.test.ts
index 1d0d3f2cd2..9e3150fa70 100644
--- a/test/git-commit-push-6530.serial.test.ts
+++ b/test/git-commit-push-6530.serial.test.ts
@@ -533,3 +533,74 @@ describe('CLI: repeated -m, --path <subdir>, and the printed repair step', () =>
expect(status(a)).toBe(' M brain/notes/other.md');
});
});
+
+describe('a checkout with no Git remote', () => {
+ /** A local-only repository (no remotes) on main whose source root is brain/. */
+ function localOnly(): { repo: string; brain: string } {
+ const repo = join(root, 'local');
+ execFileSync('git', ['init', '-q', '-b', 'main', repo], { stdio: 'ignore', env: process.env });
+ git(repo, 'config', 'user.email', '[email protected]'); git(repo, 'config', 'user.name', 'local');
+ mkdirSync(join(repo, 'brain', 'notes'), { recursive: true });
+ for (const f of ['model.md', 'other.md']) writeFileSync(join(repo, 'brain', 'notes', f), `${f} v1\n`);
+ git(repo, 'add', 'brain'); git(repo, 'commit', '-qm', 'seed');
+ return { repo, brain: join(repo, 'brain') };
+ }
+ const refusalOf = (fn: () => unknown): { code?: string; message?: string; fix?: unknown } => {
+ try { fn(); } catch (e) { return e as { code?: string; message?: string }; }
+ throw new Error('expected a refusal');
+ };
+
+ test('the printed legacy fence-repair step commits only the named path locally and says nothing was pushed', async () => {
+ const { repo, brain } = localOnly();
+ const seed = git(repo, 'rev-parse', 'HEAD');
+ writeFileSync(join(brain, 'notes', 'model.md'), 'repaired\n');
+ writeFileSync(join(brain, 'notes', 'other.md'), 'another writer\n');
+ const step = legacyCommitStep(brain, 'notes/model.md', ['no_header'], 'llm');
+ const printed: string[] = [];
+ const original = console.log;
+ console.log = (...parts: unknown[]) => { printed.push(parts.map(String).join(' ')); };
+ let code: number;
+ try { code = await runGit(argvFromCommand(step)!.slice(2)); } finally { console.log = original; }
+ expect(code).toBe(0);
+ expect(git(repo, 'rev-parse', 'HEAD^')).toBe(seed);
+ expect(git(repo, 'log', '-1', '--format=%s')).toBe('gbrain: repair fence in notes/model.md (no_header)');
+ expect(git(repo, 'log', '-1', '--format=%(trailers:key=gbrain-repair,valueonly)')).toBe('invalid_fence llm high');
+ expect(git(repo, 'show', '--name-only', '--format=', 'HEAD')).toBe('brain/notes/model.md');
+ expect(status(repo)).toBe(' M brain/notes/other.md');
+ expect(printed.join('\n')).toContain(`not pushed: ${repo} has no Git remote`);
+ });
+
+ test('commitAndPush reports committed_local with no_remote, then nothing_to_commit', () => {
+ const { repo, brain } = localOnly();
+ writeFileSync(join(brain, 'notes', 'model.md'), 'edited\n');
+ const r = commitAndPush({ repo: brain, cwd: brain, paths: ['notes/model.md'], message: 'edit' });
+ expect(r).toMatchObject({ outcome: 'committed_local', no_remote: true, branch: 'main', remote: '', paths: ['brain/notes/model.md'], checkout: 'unchanged' });
+ expect(r.sha).toBe(git(repo, 'rev-parse', 'HEAD'));
+ expect(commitAndPush({ repo: brain, cwd: brain, paths: ['notes/model.md'], message: 'again' })).toMatchObject({ outcome: 'nothing_to_commit', no_remote: true, sha: null });
+ });
+
+ test('a branch configured to a remote that does not exist still refuses git_unavailable and commits nothing', () => {
+ const { repo, brain } = localOnly();
+ const head = git(repo, 'rev-parse', 'HEAD');
+ git(repo, 'config', 'branch.main.remote', 'origin');
+ writeFileSync(join(brain, 'notes', 'model.md'), 'edited\n');
+ const err = refusalOf(() => commitAndPush({ repo: brain, cwd: brain, paths: ['notes/model.md'], message: 'edit' }));
+ expect(err.code).toBe('git_unavailable');
+ expect(String(err.message)).toContain('has no usable remote (origin); nothing was committed');
+ expect(git(repo, 'rev-parse', 'HEAD')).toBe(head);
+ expect(status(repo)).toBe(' M brain/notes/model.md');
+ });
+
+ test('publishing modes and paths-free commits refuse: there is no remote to publish to', () => {
+ const { repo, brain } = localOnly();
+ const head = git(repo, 'rev-parse', 'HEAD');
+ writeFileSync(join(brain, 'notes', 'model.md'), 'edited\n');
+ for (const opts of [{ pushOnly: true }, { pushOnly: true, keepCheckout: true }, { pending: true, message: 'm' }, { paths: ['notes/model.md'], message: 'm', advanceOnlyWhenClean: true }]) {
+ const err = refusalOf(() => commitAndPush({ repo: brain, cwd: brain, ...opts }));
+ expect(err.code).toBe('commit_paths_invalid');
+ expect(String(err.message)).toContain('has no Git remote, so there is nothing to publish to');
+ }
+ expect(refusalOf(() => commitAndPush({ repo: brain, cwd: brain, paths: [], message: 'm' })).code).toBe('commit_paths_invalid');
+ expect(git(repo, 'rev-parse', 'HEAD')).toBe(head);
+ });
+});