Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: refuse when git's dir path isn't one plain line, and treat a stopped cherry-pick or revert range as in progress (#8755)
garrytan932837accfb9
diff --git a/src/core/persistence/pending-import.ts b/src/core/persistence/pending-import.tsindex 02e93397af..1aedb85243 100644--- a/src/core/persistence/pending-import.ts+++ b/src/core/persistence/pending-import.ts@@ -128,14 +128,14 @@ export async function unmergedPath(root: string, path: string, signal?: AbortSig/*** #8755: the absolute paths of the markers a merge, cherry-pick, revert or rebase in progress leaves in `root`'s git dir- * (MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD, rebase-merge, rebase-apply); null when Git cannot name them. The caller- * checks which exist. All five live in the per-worktree git dir, which Git prints absolute and symlink-resolved, so a root- * reached through a symlink still names the real markers.+ * (MERGE_HEAD, CHERRY_PICK_HEAD, REVERT_HEAD, sequencer, rebase-merge, rebase-apply); null when Git cannot name them. The+ * caller checks which exist. All of them live in the per-worktree git dir, which Git prints absolute and symlink-resolved,+ * so a root reached through a symlink still names the real markers. Output that is not exactly one line answers null.*/export async function operationMarkerPaths(root: string, signal?: AbortSignal): Promise<string[] | null> {- const markers = ['MERGE_HEAD', 'CHERRY_PICK_HEAD', 'REVERT_HEAD', 'rebase-merge', 'rebase-apply'];+ const markers = ['MERGE_HEAD', 'CHERRY_PICK_HEAD', 'REVERT_HEAD', 'sequencer', 'rebase-merge', 'rebase-apply'];return gitRead(root, ['rev-parse', '--absolute-git-dir'], signal)- .then(out => { const [gitDir] = out.split('\n'); return gitDir ? markers.map(marker => join(gitDir, marker)) : null; },+ .then(out => { const lines = out.split('\n'); return lines.length === 2 && lines[0] && !lines[1] ? markers.map(marker => join(lines[0], marker)) : null; },error => { if (signal?.aborted) throw error; return null; });}diff --git a/test/operation-marker-paths.test.ts b/test/operation-marker-paths.test.tsindex aaba1593e3..40dc80702d 100644--- a/test/operation-marker-paths.test.ts+++ b/test/operation-marker-paths.test.ts@@ -79,3 +79,48 @@ test('a plain checkout mid-rebase sees rebase-merge', async () => {git(root, 'rebase', '--abort');expect(await present(root)).toEqual([]);});++async function readsClean(root: string): Promise<boolean> {+ return (await operationMarkerPaths(root))?.every(marker => !existsSync(marker)) === true;+}++test('a checkout whose path holds a newline never reads as clean mid-merge', async () => {+ const root = join(base, 'line\nbreak');+ mkdirSync(join(root, 'notes'), { recursive: true });+ git(root, 'init', '-q');+ writeFileSync(join(root, 'notes', 'page.md'), 'one\n');+ git(root, 'add', '.');+ git(root, 'commit', '-qm', 'one');+ git(root, 'checkout', '-qb', 'side');+ writeFileSync(join(root, 'notes', 'page.md'), 'side\n');+ git(root, 'commit', '-qam', 'side');+ git(root, 'checkout', '-q', 'main');+ writeFileSync(join(root, 'notes', 'page.md'), 'main\n');+ git(root, 'commit', '-qam', 'main');+ expect(() => git(root, 'merge', 'side')).toThrow();+ expect(existsSync(join(root, '.git', 'MERGE_HEAD'))).toBe(true);+ expect(await readsClean(root)).toBe(false);+ symlinkSync(root, join(base, 'newline-link'));+ expect(await readsClean(join(base, 'newline-link', 'notes'))).toBe(false);+});++test('a cherry-pick range stopped between picks, after the first conflict was committed, is still in progress', async () => {+ const root = repo('sequencer');+ git(root, 'checkout', '-qb', 'topic');+ writeFileSync(join(root, 'notes', 'deep', 'page.md'), 'topic\n');+ git(root, 'commit', '-qam', 'topic one');+ writeFileSync(join(root, 'notes', 'other.md'), 'two\n');+ git(root, 'add', '.');+ git(root, 'commit', '-qm', 'topic two');+ git(root, 'checkout', '-q', 'main');+ writeFileSync(join(root, 'notes', 'deep', 'page.md'), 'main\n');+ git(root, 'commit', '-qam', 'main');+ expect(() => git(root, 'cherry-pick', 'main..topic')).toThrow();+ writeFileSync(join(root, 'notes', 'deep', 'page.md'), 'resolved\n');+ git(root, 'add', '.');+ git(root, 'commit', '-q', '--no-edit');+ expect(existsSync(join(root, '.git', 'CHERRY_PICK_HEAD'))).toBe(false);+ expect(await present(root)).toEqual([join(root, '.git', 'sequencer')]);+ git(root, 'cherry-pick', '--quit');+ expect(await present(root)).toEqual([]);+});