diff --git a/publish/src/core/change-detection.ts b/publish/src/core/change-detection.ts index eae6a34..7acbbb5 100644 --- a/publish/src/core/change-detection.ts +++ b/publish/src/core/change-detection.ts @@ -53,8 +53,13 @@ export interface DiffArgs { export async function changedPostDirs(args: DiffArgs): Promise { const runner = args.runner ?? defaultRunner const stdout = await runner(['diff', '--name-only', `${args.from}..${args.to}`]) - const normalizedRoot = stripParentSegments(args.contentRoot) - return filterPostDirs(stdout.split('\n'), normalizedRoot) + const normalizedRoot = stripParentSegments(args.contentRoot).replace(/\/$/, '') + const originalRoot = args.contentRoot.replace(/\/$/, '') + if (normalizedRoot === originalRoot) { + return filterPostDirs(stdout.split('\n'), originalRoot) + } + const matched = filterPostDirs(stdout.split('\n'), normalizedRoot) + return matched.map((p) => originalRoot + p.slice(normalizedRoot.length)) } export async function allPostDirs(contentRoot: string): Promise { diff --git a/publish/tests/change-detection_test.ts b/publish/tests/change-detection_test.ts index 5a153f4..694c76f 100644 --- a/publish/tests/change-detection_test.ts +++ b/publish/tests/change-detection_test.ts @@ -94,7 +94,7 @@ Deno.test('changedPostDirs: normalisiert contentRoot mit ../-präfix', async () contentRoot: '../content/posts', runner, }) - assertEquals(dirs.sort(), ['content/posts/de/alpha', 'content/posts/en/beta']) + assertEquals(dirs.sort(), ['../content/posts/de/alpha', '../content/posts/en/beta']) }) Deno.test('changedPostDirs: normalisiert contentRoot mit mehrfachem ../-präfix', async () => { @@ -106,7 +106,19 @@ Deno.test('changedPostDirs: normalisiert contentRoot mit mehrfachem ../-präfix' contentRoot: '../../content/posts', runner, }) - assertEquals(dirs, ['content/posts/de/alpha']) + assertEquals(dirs, ['../../content/posts/de/alpha']) +}) + +Deno.test('changedPostDirs: gibt pfade mit original-contentRoot zurück (CWD-relativ)', async () => { + const runner: GitRunner = () => + Promise.resolve('content/posts/de/alpha/index.md\n') + const dirs = await changedPostDirs({ + from: 'HEAD~1', + to: 'HEAD', + contentRoot: '../content/posts', + runner, + }) + assertEquals(dirs, ['../content/posts/de/alpha']) }) Deno.test('allPostDirs: findet posts in sprach-unterordnern', async () => {