From 475ab696dad07498f89d18ea1716e68c468c5900 Mon Sep 17 00:00:00 2001 From: SitgesRun <169425442+SitgesRun@users.noreply.github.com> Date: Sun, 15 Nov 2026 17:14:33 -0800 Subject: [PATCH] A person's change puts a folder where a file stands and a file where an empty folder stands Codex's read-only review of #264 (c76a4c4): - placement.ts realTarget judges a path below a file (ENOTDIR) as it judges a path not there (ENOENT): by what is there. So restoring historical sub/a.md where sub is now a file passes the link check, and the change's deletion of the file comes first. - An empty folder where a file is written, which git does not hold and no deletion names, is removed first (rmdir, which refuses a folder that is not empty). Signed-off-by: SitgesRun <169425442+SitgesRun@users.noreply.github.com> --- extensions/pine-drama/src/core/applyChange.ts | 2 ++ extensions/pine-drama/src/core/placement.ts | 3 ++- extensions/pine-drama/src/test/entryActions.test.ts | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/extensions/pine-drama/src/core/applyChange.ts b/extensions/pine-drama/src/core/applyChange.ts index 9db6ac9..34e0a73 100644 --- a/extensions/pine-drama/src/core/applyChange.ts +++ b/extensions/pine-drama/src/core/applyChange.ts @@ -59,6 +59,8 @@ export function applyPersonChange(projectRoot: string, commitMessage: string, await removeEmptiedFolders(projectRoot, dirname(path)); } else { await mkdir(dirname(file), { recursive: true }); + // An empty folder where the file goes, which git does not hold, makes way (rmdir refuses one that is not empty). + if (statSync(file, { throwIfNoEntry: false })?.isDirectory()) { await rmdir(file); } await writeWhole(file, got); } } diff --git a/extensions/pine-drama/src/core/placement.ts b/extensions/pine-drama/src/core/placement.ts index 093e856..8b78384 100644 --- a/extensions/pine-drama/src/core/placement.ts +++ b/extensions/pine-drama/src/core/placement.ts @@ -19,7 +19,8 @@ function realTarget(path: string): string | undefined { try { return join(realpathSync(existing), ...rest); } catch (error) { - if ((error as NodeJS.ErrnoException).code !== 'ENOENT') { + // Not there, or a file stands where a folder would (ENOTDIR): judged by what is there. + if (!['ENOENT', 'ENOTDIR'].includes((error as NodeJS.ErrnoException).code ?? '')) { throw error; } } diff --git a/extensions/pine-drama/src/test/entryActions.test.ts b/extensions/pine-drama/src/test/entryActions.test.ts index a8c5e1a..ed21422 100644 --- a/extensions/pine-drama/src/test/entryActions.test.ts +++ b/extensions/pine-drama/src/test/entryActions.test.ts @@ -72,6 +72,9 @@ test("Use removes a file added since and not yet committed, leaves an object fol await mkdir(join(root, shot, 'extra'), { recursive: true }); await writeFile(join(root, shot, 'extra/notes.md'), 'the shot\'s notes'); await writeFile(join(root, shot, 'notes'), 'a file then'); + await mkdir(join(root, shot, 'sub')); + await writeFile(join(root, shot, 'sub/a.md'), 'in a folder then'); + await writeFile(join(root, shot, 'empty'), 'a file then too'); await commitFilesFoundOnDisk(root, 'The project as found'); const [first] = await listHistoryOfShownFile(root, shot); // Since: extra/ became an object of its own, notes became a folder, and a file was added by hand, not committed. @@ -80,6 +83,10 @@ test("Use removes a file added since and not yet committed, leaves an object fol await rm(join(root, shot, 'notes')); await mkdir(join(root, shot, 'notes')); await writeFile(join(root, shot, 'notes/a.md'), 'a folder now'); + await rm(join(root, shot, 'sub'), { recursive: true }); + await writeFile(join(root, shot, 'sub'), 'a file now'); + await rm(join(root, shot, 'empty')); + await mkdir(join(root, shot, 'empty')); await git(['add', '-A'], root); await git(['-c', 'user.name=person', '-c', 'user.email=p@x', 'commit', '-q', '-m', 'since'], root); await writeFile(join(root, shot, 'scratch.md'), 'by hand, not committed'); @@ -87,6 +94,8 @@ test("Use removes a file added since and not yet committed, leaves an object fol assert.equal(existsSync(join(root, shot, 'scratch.md')), false, 'a file the folder did not hold then goes, though no commit held it'); assert.equal(await readFile(join(root, shot, 'extra/notes.md'), 'utf8'), 'the extra\'s own notes', 'an object folded inside is its own'); assert.equal(await readFile(join(root, shot, 'notes'), 'utf8'), 'a file then', 'a file takes the place of the folder that stands there now'); + assert.equal(await readFile(join(root, shot, 'sub/a.md'), 'utf8'), 'in a folder then', 'and a folder the place of a file'); + assert.equal(await readFile(join(root, shot, 'empty'), 'utf8'), 'a file then too', 'an empty folder, which git does not hold, makes way'); assert.match((await git(['log', '--format=%an', '-2'], root)).stdout, /client-found-changes-on-disk/, 'the hand-made file is kept in history first'); });