Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(git): a pending file flagged both skip-worktree and assume-unchanged no longer blocks the other pending pages (GST-2118)

garrytand4188bbc1e39
diff --git a/src/core/git/commit-push.ts b/src/core/git/commit-push.ts
index 61829b5dce..6147b50f93 100644
--- a/src/core/git/commit-push.ts
+++ b/src/core/git/commit-push.ts
@@ -598,7 +598,7 @@ function commitPaths(root: string, rel: string[], message: string, scope: Commit
const before = indexEntries(root, rel);
// GST-2118: git add refuses a named skip-worktree file that is on disk; it is left to the skipped-path check, so the other paths still commit.
const sparse = new Set(gitOk(root, ['ls-files', '-v', '-z', '--', ...literalPathspecs(rel)], 'ls-files -v').split('\0')
- .filter(entry => entry.startsWith('S ') && rel.includes(entry.slice(2)) && existsSync(join(root, entry.slice(2)))).map(entry => entry.slice(2)));
+ .filter(entry => /^[sS] /.test(entry) && rel.includes(entry.slice(2)) && existsSync(join(root, entry.slice(2)))).map(entry => entry.slice(2)));
const add = rel.some(p => !sparse.has(p)) ? withIndexRetry(root, ['add', '-A', '--', ...literalPathspecs(rel.filter(p => !sparse.has(p)))], 'git add') : { code: 0, stdout: '', stderr: '' };
if (add.code !== 0) {
throw opError('commit_paths_invalid', 'git add refused the given paths.', add.stderr.trim().slice(0, 300) || 'Check the paths exist or are tracked.');
diff --git a/test/pending-ledger-flagged-gst2118.test.ts b/test/pending-ledger-flagged-gst2118.test.ts
index f2359d2d42..f3799ac5ca 100644
--- a/test/pending-ledger-flagged-gst2118.test.ts
+++ b/test/pending-ledger-flagged-gst2118.test.ts
@@ -159,6 +159,22 @@ test('a skip-worktree file left in the ledger does not fail a later write-throug
expect(ledger(brain)).toEqual(['people/alice-example.md']);
});
+test('a file flagged both skip-worktree and assume-unchanged does not stop other pending pages from committing', async () => {
+ const brain = fixture('both-flags');
+ git(brain, 'update-index', '--skip-worktree', '--', 'people/alice-example.md');
+ git(brain, 'update-index', '--assume-unchanged', '--', 'people/alice-example.md');
+ expect(git(brain, 'ls-files', '-v', '--', 'people/alice-example.md')).toStartWith('s ');
+ 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', 'A pending edit.'));
+ notePending(brain, ['people/alice-example.md', 'people/bob-example.md']);
+ writeFileSync(join(brain, 'people', 'carol-example.md'), page('Carol', 'New page.'));
+ await withEnv(identity, async () => commitPathsLocked(brain, [join(brain, 'people', 'carol-example.md')], 'w', { lockWaitMs: 1000 }));
+ expect(headBlob(brain, 'people/carol-example.md')).toContain('New page.');
+ expect(headBlob(brain, 'people/bob-example.md')).toContain('A pending edit.');
+ expect(git(brain, 'diff', '--cached', '--name-only').trim()).toBe('');
+ expect(ledger(brain)).toEqual(['people/alice-example.md']);
+});
+
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.'));