Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions extensions/pine-drama/src/core/applyChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion extensions/pine-drama/src/core/placement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
9 changes: 9 additions & 0 deletions extensions/pine-drama/src/test/entryActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -80,13 +83,19 @@ 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');
await runCardAction(root, { action: 'use', object: shot, commit: first.commit }, never);
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');
});

Expand Down
Loading