Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge commit 'f86d3a4a9202a79470925868c5b07066b4299731' into capy/gst2118-pending-ledger-flagged

garrytan190941565092
diff --cc CHANGELOG.md
index 4ed41b5ac9,23b89b9e5a..f56e9eb455
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -10,23 -10,6 +10,23 @@@ credits are retained; no result has bee
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [0.60.632.0] - 2026-11-09
+
+**A page write that git could not commit because the file is flagged assume-unchanged or skip-worktree now stays in the write-through pending ledger.** gbrain's own page writes and `gbrain git commit-push --pending` asked `git status` which pending files were still uncommitted, and status does not show a flagged entry, so the write was left uncommitted, dropped from the ledger (doctor `dirty_age` never reported it and no later write retried it), and `--pending` answered `nothing_to_commit` with exit 0. A flagged file whose bytes differ from HEAD now counts as uncommitted.
+
+| Situation | Before | After |
+| --- | --- | --- |
- | A page write to a flagged file | not committed, not in the ledger | not committed, kept in the ledger; doctor reports it as `dirty_age` after 30 minutes |
++| A page write to a flagged file | not committed, not in the ledger | not committed, kept in the ledger (the write itself fails `commit_paths_skipped`, as in 0.60.630.0); doctor reports it as `dirty_age` after 30 minutes |
+| A later page write while a flagged file is in the ledger | the entry was settled away | the entry is committed beside the new write when git picks it up, and otherwise stays |
+| `gbrain git commit-push --pending` with a flagged pending file | `nothing_to_commit`, exit 0 | `commit_paths_skipped` naming the file, exit 1; the ledger keeps it |
+| A page write or `gbrain git commit-push` naming a modified skip-worktree file that is on disk | `git add` refused it: `commit_paths_invalid`, nothing committed, and a page write dropped the file from the ledger | the other paths are committed; the file is reported as skipped (`commit_paths_skipped`, reason `skip_worktree`, exit 1 from `commit-push`) and a page write keeps it in the ledger |
+
+### Itemized changes
+
- - `src/core/git/commit-push.ts`: the pending-ledger check (`dirtyPaths`, used by the write-through commit, `--pending`, ledger settling and doctor `dirty_age`) also counts flagged entries whose bytes differ from HEAD, using the same check as the GST-2116 skipped-path detection (`flaggedChanges`), where an entry git cannot hash counts as changed instead of failing the check; `commitPaths` no longer hands `git add` a named skip-worktree file that is on disk (git refuses it and failed every named path), and reports it as skipped; the write-through commit notes its own flagged files that git left out in the ledger, and ledger settling keeps every entry when the check fails.
++- `src/core/git/commit-push.ts`: the pending-ledger check (`dirtyPaths`, used by the write-through commit, `--pending`, ledger settling and doctor `dirty_age`) also counts flagged entries whose bytes differ from HEAD, using the same check as the GST-2116 skipped-path detection (`flaggedChanges`), where an entry git cannot hash counts as changed instead of failing the check and a flagged gitlink is left out; `commitPaths` no longer hands `git add` a named skip-worktree file that is on disk (git refuses it and failed every named path), and reports it as skipped; the write-through commit notes its own flagged files that git left out in the ledger, and ledger settling keeps every entry when the check fails.
+- Docs: `docs/guides/shared-checkout-git.md` (pending write-through section).
+- Tests: `test/pending-ledger-flagged-gst2118.test.ts` (real git and the real CLI: a flagged write-through file stays in the ledger and doctor's dirty check sees it, a later write commits an older flagged entry instead of settling it away, `--pending` on a flagged file fails and keeps the entry, and a flagged entry git cannot hash is kept while a later write still commits, a write to a named skip-worktree file beside another page commits the other page and keeps the file for `--pending` to report, and an ordinary pending file as the control). Five of its six cases fail without the fix; the control passes.
+
## [0.60.631.0] - 2026-11-09
**A long conversation that keeps growing is no longer re-extracted, and re-paid for, on every new message.** Automatic event extraction reads a page's title, date, attendees and the first 12,000 characters of its body. On a conversation longer than that, each new message recorded a new revision, and each revision paid for another extraction call on exactly the same text. The model words each event a little differently every time, event pages are named after that wording, and an extraction of a page longer than 12,000 characters never retired the previous one, so every run added a fresh copy of every event. One page could collect dozens of paid calls and hundreds of duplicate events. Now a revision that changes nothing extraction reads (text, title, date, attendees, privacy) makes no call and writes nothing (it records `judge_input_unchanged`); a window the judge keeps failing on is paid for at most the page's attempt limit across all revisions, then records `judge_input_failed` until the text changes or a backfill asks again; and a re-extraction that re-read all the text the page's live events came from (for example after a title change, or the first time a conversation grows past 12,000 characters) replaces those events instead of adding to them. A page whose opening text was edited still keeps its earlier events, as before. Text past the first 12,000 characters is still not extracted; incremental coverage of the tail is tracked in #9013. Reported by @andreineacsu.
diff --cc docs/guides/shared-checkout-git.md
index 9af4ab90e6,2a27f282be..86a30f330d
--- a/docs/guides/shared-checkout-git.md
+++ b/docs/guides/shared-checkout-git.md
@@@ -181,7 -182,7 +182,7 @@@ Follow the error's `fix.next` as th
| `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. |
| <a id="checkout_not_a_source"></a>`checkout_not_a_source` | 1 | The checkout commit-push resolved from the working directory (no `--path`) is not one of the brain's source checkouts on this host, typically a wrapper that changed into another repository; nothing was staged. The message lists the brain's checkouts. Tell the user to make the script pass `--path` with the absolute brain checkout. A repository that only encloses a source checkout (a brain cloned inside another repository) is not one; a source registered at a subdirectory its checkout tracks is. A host whose brain records no source checkout, or a checkout with `gbrain.sourceRoot` set, is never refused this way. |
| `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. |
- | <a id="commit_paths_skipped"></a>`commit_paths_skipped` | 1 | Git left a named path out of the commit: a modified file flagged assume-unchanged or skip-worktree (`reason` `assume_unchanged`, `skip_worktree`) or a file inside a nested Git repository (`not_staged`). The other named paths were committed (and, on a classic checkout, pushed); `detail` lists each skipped path, the commit and the pushed head. Check the flags with `git ls-files -v -- <path>`; clear them only after the user agrees, one flag per call (`git update-index --no-assume-unchanged -- <path>`, `git update-index --no-skip-worktree -- <path>`; given both, git clears only the first), and remember skip-worktree is often set on purpose to keep local edits out of commits, or move the file out of the nested repository, then rerun. A skip-worktree file absent from disk (a sparse checkout) and ignored files under a named directory are not reported. |
-| <a id="commit_paths_skipped"></a>`commit_paths_skipped` | 1 | Git left a named path out of the commit although `git add` exited 0: a modified file flagged assume-unchanged or skip-worktree (`reason` `assume_unchanged`, `skip_worktree`) or a file inside a nested Git repository (`not_staged`). The other named paths were committed (and, on a classic checkout, pushed); `detail` lists each skipped path, the commit and the pushed head, or the push failure (`publish`) when the push failed too. Check the flags with `git ls-files -v -- <path>`; clear them only after the user agrees, one flag per call (`git update-index --no-assume-unchanged -- <path>`, `git update-index --no-skip-worktree -- <path>`; given both, git clears only the first), and remember skip-worktree is often set on purpose to keep local edits out of commits, or move the file out of the nested repository, then rerun. A skip-worktree file absent from disk (a sparse checkout), a flagged gitlink and ignored files under a named directory are not reported. |
++| <a id="commit_paths_skipped"></a>`commit_paths_skipped` | 1 | Git left a named path out of the commit: a modified file flagged assume-unchanged or skip-worktree (`reason` `assume_unchanged`, `skip_worktree`) or a file inside a nested Git repository (`not_staged`). The other named paths were committed (and, on a classic checkout, pushed); `detail` lists each skipped path, the commit and the pushed head, or the push failure (`publish`) when the push failed too. Check the flags with `git ls-files -v -- <path>`; clear them only after the user agrees, one flag per call (`git update-index --no-assume-unchanged -- <path>`, `git update-index --no-skip-worktree -- <path>`; given both, git clears only the first), and remember skip-worktree is often set on purpose to keep local edits out of commits, or move the file out of the nested repository, then rerun. A skip-worktree file absent from disk (a sparse checkout), a flagged gitlink and ignored files under a named directory are not reported. |
| `commit_prestaged_paths` | 1 | Another writer staged files under a directory you named; nothing was staged or committed. Name your own files explicitly. Unstage the others (`git restore --staged -- <file>`, which keeps their bytes) only after the user agrees. |
| `commit_outside_source_root` | 1 | The commit, or a local commit about to be published, changes files outside the brain's [source root](#source-roots); nothing was pushed. Show the user `git show --stat <sha>`; rerun with `--allow-outside-source-root` only if they want it published. |
| `git_index_locked` | 1 | A git command that does not take the writer lock held `index.lock`. Retry once after a few seconds. |
diff --cc src/core/git/commit-push.ts
index c1475ec6f4,6c2433c93e..c237b38bfb
--- a/src/core/git/commit-push.ts
+++ b/src/core/git/commit-push.ts
@@@ -436,35 -436,34 +436,42 @@@ interface CommitScope { roots: string[]
/** A named path `git add -A` left out of the index while still exiting 0 (GST-2116). */
export interface SkippedPath { path: string; reason: 'assume_unchanged' | 'skip_worktree' | 'not_staged' }
-/**
- * GST-2116: the named paths whose bytes on disk HEAD still lacks once the commit step is done. `git add -A` stages
- * nothing and exits 0 for a modified entry flagged assume-unchanged or skip-worktree (`ls-files -v`: lower case, or S;
- * `commit --only` may still pick one up beside another path, so the check reads HEAD) and for a file inside an untracked
- * nested repository. A skip-worktree entry absent from disk is a sparse checkout, not a change, and a flagged gitlink
- * is left out (its commit lives in the nested repository, which hash-object cannot read). Ignored files under a named
- * directory are left out as git leaves them; a named ignored file is refused by `git add` itself.
- */
-function unstagedPaths(root: string, rel: string[], listed: string[]): SkippedPath[] {
- const skipped = new Map<string, SkippedPath['reason']>();
+/** The flagged index entries in `listed` (`ls-files -v`: lower case for assume-unchanged, S for skip-worktree) whose bytes on disk HEAD lacks. A skip-worktree entry absent from disk is a sparse checkout, not a change. */
+function flaggedChanges(root: string, listed: string[]): SkippedPath[] {
+ const changed: SkippedPath[] = [];
- for (const line of listed.filter(entry => /^[a-zS] /.test(entry))) {
+ const flagged = listed.filter(entry => /^[a-zS] /.test(entry));
+ const gitlinks = new Set(flagged.length
+ ? gitOk(root, ['ls-files', '-s', '-z', '--', ...literalPathspecs(flagged.map(line => line.slice(2)))], 'ls-files -s')
+ .split('\0').filter(entry => entry.startsWith('160000 ')).map(entry => entry.slice(entry.indexOf('\t') + 1))
+ : []);
+ for (const line of flagged) {
const path = line.slice(2);
+ if (gitlinks.has(path)) continue;
const abs = join(root, path);
const reason = /^[sS]/.test(line) ? 'skip_worktree' as const : 'assume_unchanged' as const;
const stat = (() => { try { return lstatSync(abs); } catch { return null; } })();
if (!stat && reason === 'skip_worktree') continue;
- const disk = !stat ? null : stat.isSymbolicLink()
- ? gitOk(root, ['hash-object', '--stdin'], 'hash-object', { input: readlinkSync(abs) })
- : gitOk(root, ['hash-object', '--', path], 'hash-object');
+ const hashed = !stat ? null : stat.isSymbolicLink()
+ ? git(root, ['hash-object', '--stdin'], { input: readlinkSync(abs) })
+ : git(root, ['hash-object', '--', path]);
+ // An entry git cannot hash (a missing required filter, an unreadable file, a directory now) counts as changed, so it is reported, never dropped.
+ const disk = hashed && (hashed.code === 0 ? hashed.stdout.trim() : undefined);
const committed = git(root, ['rev-parse', '--verify', '--quiet', `HEAD:${path}`]).stdout.trim() || null;
- if (disk !== committed) skipped.set(path, reason);
+ if (disk !== committed) changed.push({ path, reason });
}
+ return changed;
+}
+
+/**
+ * GST-2116: the named paths whose bytes on disk HEAD still lacks once the commit step is done. `git add -A` stages
+ * nothing and exits 0 for a modified entry flagged assume-unchanged or skip-worktree (`ls-files -v`: lower case, or S;
+ * `commit --only` may still pick one up beside another path, so the check reads HEAD) and for a file inside an untracked
- * nested repository. A skip-worktree entry absent from disk is a sparse checkout, not a change. Ignored files under a
- * named directory are left out as git leaves them; a named ignored file is refused by `git add` itself.
++ * nested repository. A skip-worktree entry absent from disk is a sparse checkout, not a change, and a flagged gitlink
++ * is left out (its commit lives in the nested repository, which hash-object cannot read). Ignored files under a named
++ * directory are left out as git leaves them; a named ignored file is refused by `git add` itself.
+ */
+function unstagedPaths(root: string, rel: string[], listed: string[]): SkippedPath[] {
+ const skipped = new Map(flaggedChanges(root, listed).map(s => [s.path, s.reason]));
for (const path of unindexedFiles(root, rel, listed)) if (!skipped.has(path)) skipped.set(path, 'not_staged');
// Only a named directory can hide an unstaged change from the two checks above (a nested repository inside it).
const dirs = rel.filter(path => { try { return lstatSync(join(root, path)).isDirectory(); } catch { return false; } });
@@@ -598,20 -600,21 +611,21 @@@ function commitPaths(root: string, rel
// A file git did not index would fail `commit --only` for every path; it is left out here and reported as skipped.
const listed = gitOk(root, ['ls-files', '-v', '-z', '--', ...literalPathspecs(paths)], 'ls-files -v').split('\0').filter(Boolean);
const unindexed = new Set(unindexedFiles(root, paths, listed));
- const staged = paths.filter(p => !unindexed.has(p));
+ const staged = paths.filter(p => !unindexed.has(p) && !sparse.has(p));
- if (!staged.length || git(root, ['diff', '--cached', '--quiet', '--', ...literalPathspecs(staged)]).code === 0) return { sha: null, skipped: unstagedPaths(root, paths, listed) };
- const env = { [COMMIT_VIA_ENV]: scope.lockPath, ...(scope.markHeld ? { [COMMIT_LOCK_ENV]: scope.lockPath } : {}) };
- // #7759: literal per path, never git's global --literal-pathspecs: Git exports that to the commit's hooks, where a
- // guard's glob pathspec ('*.json') then matches nothing and lets the commit through.
- recordIntent(root, { writer: 'commit_push', head_before: git(root, ['rev-parse', '--verify', '--quiet', 'HEAD']).stdout.trim() || null, message });
- const commit = withIndexRetry(root, ['commit', '--only', '-m', message, '--', ...literalPathspecs(staged)], 'git commit', env);
- if (commit.code !== 0) {
- throw opError('git_unavailable', `git commit failed in ${root}; the paths were unstaged again and keep their bytes.`,
- `${commit.stderr.trim().slice(0, 300)} A missing git identity (user.name, user.email) or a refusing pre-commit hook are common causes.`);
+ if (!staged.length || git(root, ['diff', '--cached', '--quiet', '--', ...literalPathspecs(staged)]).code === 0) {
+ landed = { committed: false, paths, listed };
+ } else {
+ const env = { [COMMIT_VIA_ENV]: scope.lockPath, ...(scope.markHeld ? { [COMMIT_LOCK_ENV]: scope.lockPath } : {}) };
+ // #7759: literal per path, never git's global --literal-pathspecs: Git exports that to the commit's hooks, where a
+ // guard's glob pathspec ('*.json') then matches nothing and lets the commit through.
+ recordIntent(root, { writer: 'commit_push', head_before: git(root, ['rev-parse', '--verify', '--quiet', 'HEAD']).stdout.trim() || null, message });
+ const commit = withIndexRetry(root, ['commit', '--only', '-m', message, '--', ...literalPathspecs(staged)], 'git commit', env);
+ if (commit.code !== 0) {
+ throw opError('git_unavailable', `git commit failed in ${root}; the paths were unstaged again and keep their bytes.`,
+ `${commit.stderr.trim().slice(0, 300)} A missing git identity (user.name, user.email) or a refusing pre-commit hook are common causes.`);
+ }
+ landed = { committed: true, paths, listed };
}
- const sha = gitOk(root, ['rev-parse', 'HEAD'], 'rev-parse HEAD');
- recordCommit(root, { sha, writer: 'commit_push' });
- return { sha, skipped: unstagedPaths(root, paths, listed) };
} catch (e) {
try { restoreIndex(root, rel, before); } catch { /* the index lock outlasted the retries; the error below still stands */ }
throw e;
@@@ -735,10 -740,11 +754,14 @@@ export function commitPathsLocked(repo
if (!pending.length) throw e;
commit = commitPaths(root, paths, message, scope);
}
+ // GST-2118: a file git left out stays in the ledger, so doctor dirty_age reports it and --pending retries it loudly.
+ const skipped = commit.skipped.map(s => s.path).filter(p => paths.includes(p));
+ if (skipped.length) notePending(root, skipped);
settlePending(root);
+ 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);
diff --cc test/pending-ledger-flagged-gst2118.test.ts
index 2e8653cfaf,0000000000..854eed7c57
mode 100644,000000..100644
--- a/test/pending-ledger-flagged-gst2118.test.ts
+++ b/test/pending-ledger-flagged-gst2118.test.ts
@@@ -1,128 -1,0 +1,136 @@@
+/**
+ * GST-2118: gbrain's own write-through commit (`commitPathsLocked`) and `gbrain git commit-push --pending` read
+ * "is this file still uncommitted?" from `git status`, which is blind to an entry flagged assume-unchanged. A
+ * write-through file with that flag was not committed, yet the pending ledger dropped it (so doctor `dirty_age`
+ * never saw it and nothing retried it), and `--pending` answered nothing_to_commit with exit 0. A flagged file whose
+ * bytes differ from HEAD now counts as uncommitted: the ledger keeps it, doctor reports it, and `--pending` fails
+ * `commit_paths_skipped` naming it. Seams: none; real git in temp repositories, the real CLI for `--pending`.
+ * DB-free, so there is no engine axis.
+ */
+import { afterAll, expect, test } from 'bun:test';
+import { execFileSync } from 'node:child_process';
+import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { commitPathsLocked, notePending, pendingWriteThroughStillDirty, readPendingWriteThrough } from '../src/core/git/commit-push.ts';
+import { runCli } from './helpers/cli-spawn.ts';
+import { withEnv } from './helpers/with-env.ts';
+
+const dir = realpathSync(mkdtempSync(join(tmpdir(), 'gbrain-pending-flagged-')));
+afterAll(() => rmSync(dir, { recursive: true, force: true }));
+const identity = { GIT_AUTHOR_NAME: 'Example', GIT_AUTHOR_EMAIL: '[email protected]', GIT_COMMITTER_NAME: 'Example', GIT_COMMITTER_EMAIL: '[email protected]' };
+const git = (root: string, ...args: string[]) => execFileSync('git', ['-C', root, '-c', 'user.name=Example', '-c', '[email protected]',
+ '-c', 'commit.gpgsign=false', ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, ...identity } }).trim();
+const page = (title: string, body: string) => `---\ntitle: ${title}\n---\n${body}\n`;
+
+/** A brain checkout with two committed pages; `remote` gives it a bare upstream (`--pending` publishes, so it needs one). */
+function fixture(name: string, remote = false): string {
+ const brain = join(dir, name);
+ if (remote) {
+ execFileSync('git', ['init', '-q', '--bare', '-b', 'main', `${brain}.git`]);
+ execFileSync('git', ['clone', '-q', `${brain}.git`, brain], { stdio: 'ignore' });
+ git(brain, 'checkout', '-q', '-b', 'main');
+ } else {
+ execFileSync('git', ['init', '-q', '-b', 'main', brain]);
+ }
+ mkdirSync(join(brain, 'people'));
+ writeFileSync(join(brain, 'people', 'alice-example.md'), page('Alice', 'First version.'));
+ writeFileSync(join(brain, 'people', 'bob-example.md'), page('Bob', 'First version.'));
+ git(brain, 'add', '.'); git(brain, 'commit', '-qm', 'init');
+ if (remote) git(brain, 'push', '-q', '-u', 'origin', 'main');
+ return brain;
+}
+/** gbrain writes the page, but the entry is flagged assume-unchanged (an editor or indexer left it), so git add skips it. */
+const writeFlagged = (brain: string, path: string) => {
+ git(brain, 'update-index', '--assume-unchanged', '--', path);
+ writeFileSync(join(brain, path), page('Hidden', 'A write-through edit git add does not see.'));
+};
+const headBlob = (brain: string, path: string) => git(brain, 'show', `HEAD:${path}`);
+const ledger = (brain: string) => readPendingWriteThrough(brain).map(e => e.path);
+
+test('a flagged write-through file is not committed and stays in the pending ledger, where doctor dirty_age sees it', async () => {
+ const brain = fixture('locked-flagged');
+ writeFlagged(brain, 'people/alice-example.md');
- const sha = await withEnv(identity, async () => commitPathsLocked(brain, [join(brain, 'people', 'alice-example.md')], 'gbrain: write-through people/alice-example', { lockWaitMs: 1000 }));
- expect(sha).toBeNull();
++ const thrown = await withEnv(identity, async () => {
++ try { commitPathsLocked(brain, [join(brain, 'people', 'alice-example.md')], 'gbrain: write-through people/alice-example', { lockWaitMs: 1000 }); } catch (e) { return e as { code?: string; detail?: string }; }
++ return null;
++ });
++ expect(thrown?.code).toBe('commit_paths_skipped');
++ expect(JSON.parse(thrown!.detail!).committed).toBeNull();
+ expect(headBlob(brain, 'people/alice-example.md')).toContain('First version.');
+ expect(ledger(brain)).toEqual(['people/alice-example.md']);
+ expect(pendingWriteThroughStillDirty(brain).map(e => e.path)).toEqual(['people/alice-example.md']);
+});
+
+test('a later write-through commits an older flagged ledger entry beside its own file instead of settling it away', async () => {
+ const brain = fixture('locked-settle');
+ writeFlagged(brain, 'people/alice-example.md');
+ notePending(brain, ['people/alice-example.md']);
+ writeFileSync(join(brain, 'people', 'bob-example.md'), page('Bob', 'Second version.'));
+ const sha = await withEnv(identity, async () => commitPathsLocked(brain, [join(brain, 'people', 'bob-example.md')], 'gbrain: write-through people/bob-example', { lockWaitMs: 1000 }));
+ expect(sha).not.toBeNull();
+ expect(headBlob(brain, 'people/bob-example.md')).toContain('Second version.');
+ expect(headBlob(brain, 'people/alice-example.md')).toContain('A write-through edit git add does not see.');
+ expect(ledger(brain)).toEqual([]);
+});
+
+test('a flagged ledger entry git cannot hash is kept, and a later write-through still commits its own file', async () => {
+ const brain = fixture('locked-unhashable');
+ git(brain, 'update-index', '--assume-unchanged', '--', 'people/alice-example.md');
+ rmSync(join(brain, 'people', 'alice-example.md'));
+ mkdirSync(join(brain, 'people', 'alice-example.md'));
+ writeFileSync(join(brain, 'people', 'alice-example.md', 'note.md'), page('Note', 'A directory where a page was.'));
+ notePending(brain, ['people/alice-example.md']);
+ writeFileSync(join(brain, 'people', 'bob-example.md'), page('Bob', 'Second version.'));
+ const sha = await withEnv(identity, async () => commitPathsLocked(brain, [join(brain, 'people', 'bob-example.md')], 'gbrain: write-through people/bob-example', { lockWaitMs: 1000 }));
+ expect(sha).not.toBeNull();
+ expect(headBlob(brain, 'people/bob-example.md')).toContain('Second version.');
+ expect(ledger(brain)).toEqual(['people/alice-example.md']);
+ expect(pendingWriteThroughStillDirty(brain).map(e => e.path)).toEqual(['people/alice-example.md']);
+});
+
+test('a write-through to a skip-worktree file git add refuses stays in the ledger, and --pending reports it as skipped', async () => {
+ const brain = fixture('locked-skip-worktree', true);
+ git(brain, 'update-index', '--skip-worktree', '--', 'people/alice-example.md');
+ writeFileSync(join(brain, 'people', 'alice-example.md'), page('Hidden', 'A write-through edit git add refuses.'));
+ writeFileSync(join(brain, 'people', 'bob-example.md'), page('Bob', 'Second version.'));
- const sha = await withEnv(identity, async () => commitPathsLocked(brain, [join(brain, 'people', 'alice-example.md'), join(brain, 'people', 'bob-example.md')], 'gbrain: write-through', { lockWaitMs: 1000 }));
- expect(sha).not.toBeNull();
++ const thrown = await withEnv(identity, async () => {
++ try { commitPathsLocked(brain, [join(brain, 'people', 'alice-example.md'), join(brain, 'people', 'bob-example.md')], 'gbrain: write-through', { lockWaitMs: 1000 }); } catch (e) { return e as { code?: string; detail?: string }; }
++ return null;
++ });
++ expect(thrown?.code).toBe('commit_paths_skipped');
++ expect(JSON.parse(thrown!.detail!).committed).toBe(git(brain, 'rev-parse', 'HEAD'));
+ expect(headBlob(brain, 'people/bob-example.md')).toContain('Second version.');
+ expect(headBlob(brain, 'people/alice-example.md')).toContain('First version.');
+ expect(ledger(brain)).toEqual(['people/alice-example.md']);
+ const r = await runCli(['git', 'commit-push', '--json', '--path', brain, '--pending'], { cwd: dir, home: join(dir, 'skip-home'), env: identity });
+ expect(r.exitCode).not.toBe(0);
+ const e = JSON.parse(r.stdout) as { code: string; message: string };
+ expect(e.code).toBe('commit_paths_skipped');
+ expect(e.message).toContain('people/alice-example.md');
+ expect(ledger(brain)).toEqual(['people/alice-example.md']);
+}, 60_000);
+
+test('commit-push --pending fails commit_paths_skipped on a flagged pending file and keeps its ledger entry', async () => {
+ const brain = fixture('pending-flagged', true);
+ writeFlagged(brain, 'people/alice-example.md');
+ notePending(brain, ['people/alice-example.md']);
+ const before = git(brain, 'rev-parse', 'HEAD');
+ const r = await runCli(['git', 'commit-push', '--json', '--path', brain, '--pending'], { cwd: dir, home: join(dir, 'pending-home'), env: identity });
+ expect(r.exitCode).not.toBe(0);
+ const e = JSON.parse(r.stdout) as { code: string; message: string };
+ expect(e.code).toBe('commit_paths_skipped');
+ expect(e.message).toContain('people/alice-example.md');
+ expect(git(brain, 'rev-parse', 'HEAD')).toBe(before);
+ expect(ledger(brain)).toEqual(['people/alice-example.md']);
+}, 60_000);
+
+test('control: an ordinary pending file is committed by --pending and the ledger settles empty', async () => {
+ const brain = fixture('pending-ok', true);
+ writeFileSync(join(brain, 'people', 'alice-example.md'), page('Alice', 'Second version.'));
+ notePending(brain, ['people/alice-example.md']);
+ const r = await runCli(['git', 'commit-push', '--json', '--path', brain, '--pending'], { cwd: dir, home: join(dir, 'ok-home'), env: identity });
+ expect(r.exitCode).toBe(0);
+ expect(headBlob(brain, 'people/alice-example.md')).toContain('Second version.');
+ expect(ledger(brain)).toEqual([]);
+}, 60_000);