mirror of
https://github.com/backnotprop/plannotator.git
synced 2026-09-14 14:17:26 +08:00
fix(review): resolve repo root for untracked file discovery (#450)
git ls-files scopes to the CWD subtree and returns CWD-relative paths, unlike git diff HEAD which covers the full repo with root-relative paths. When the hook process inherits a subdirectory CWD, untracked files outside that subtree are silently dropped and paths for files inside it are wrong. Resolve the repo root via rev-parse --show-toplevel and use it as the CWD for both git ls-files and git diff --no-index in getUntrackedFileDiffs. Fixes #449
This commit is contained in:
@@ -174,9 +174,20 @@ async function getUntrackedFileDiffs(
|
||||
dstPrefix = "b/",
|
||||
cwd?: string,
|
||||
): Promise<string> {
|
||||
// git ls-files scopes to the CWD subtree and returns CWD-relative paths,
|
||||
// unlike git diff HEAD which always covers the full repo with root-relative
|
||||
// paths. Resolve the repo root so untracked files from the entire repo are
|
||||
// included and their paths match the tracked-diff output.
|
||||
const toplevelResult = await runtime.runGit(
|
||||
["rev-parse", "--show-toplevel"],
|
||||
{ cwd },
|
||||
);
|
||||
const rootCwd =
|
||||
toplevelResult.exitCode === 0 ? toplevelResult.stdout.trim() : cwd;
|
||||
|
||||
const lsResult = await runtime.runGit(
|
||||
["ls-files", "--others", "--exclude-standard"],
|
||||
{ cwd },
|
||||
{ cwd: rootCwd },
|
||||
);
|
||||
if (lsResult.exitCode !== 0) return "";
|
||||
|
||||
@@ -199,7 +210,7 @@ async function getUntrackedFileDiffs(
|
||||
"/dev/null",
|
||||
file,
|
||||
],
|
||||
{ cwd },
|
||||
{ cwd: rootCwd },
|
||||
);
|
||||
return diffResult.stdout;
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user