From b89442bf5c4cea2c599b190794f18f53de8a1344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lohrer?= Date: Tue, 21 Apr 2026 10:10:01 +0200 Subject: [PATCH] =?UTF-8?q?fix(publish):=20changedPostDirs=20normalisiert?= =?UTF-8?q?=20../-pr=C3=A4fix=20im=20contentRoot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/src/core/change-detection.ts | 7 ++++++- publish/tests/change-detection_test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/publish/src/core/change-detection.ts b/publish/src/core/change-detection.ts index 2dacde0..eae6a34 100644 --- a/publish/src/core/change-detection.ts +++ b/publish/src/core/change-detection.ts @@ -4,6 +4,10 @@ function escapeRegex(s: string): string { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') } +function stripParentSegments(path: string): string { + return path.replace(/^(\.\.\/)+/, '') +} + export function filterPostDirs(lines: string[], contentRoot: string): string[] { const root = contentRoot.replace(/\/$/, '') const prefix = root + '/' @@ -49,7 +53,8 @@ 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}`]) - return filterPostDirs(stdout.split('\n'), args.contentRoot) + const normalizedRoot = stripParentSegments(args.contentRoot) + return filterPostDirs(stdout.split('\n'), normalizedRoot) } export async function allPostDirs(contentRoot: string): Promise { diff --git a/publish/tests/change-detection_test.ts b/publish/tests/change-detection_test.ts index 300287c..5a153f4 100644 --- a/publish/tests/change-detection_test.ts +++ b/publish/tests/change-detection_test.ts @@ -85,6 +85,30 @@ Deno.test('filterPostDirs: _drafts unter sprach-ebene wird ignoriert', () => { assertEquals(filterPostDirs(lines, 'content/posts'), ['content/posts/de/real']) }) +Deno.test('changedPostDirs: normalisiert contentRoot mit ../-präfix', async () => { + const runner: GitRunner = () => + Promise.resolve('content/posts/de/alpha/index.md\ncontent/posts/en/beta/index.md\n') + const dirs = await changedPostDirs({ + from: 'HEAD~1', + to: 'HEAD', + contentRoot: '../content/posts', + runner, + }) + assertEquals(dirs.sort(), ['content/posts/de/alpha', 'content/posts/en/beta']) +}) + +Deno.test('changedPostDirs: normalisiert contentRoot mit mehrfachem ../-präfix', 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 () => { const tmp = await Deno.makeTempDir() try {