mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-22 03:18:54 +08:00
fix: only limit fetch depth when the checkout is already shallow (#1647)
restoreConfigFromBase and setupBranch pass --depth to every git fetch. On a checkout made with fetch-depth: 0 that does not just cap the download: it truncates the history already present and marks the repository shallow, which drops the merge base with the base branch. `git log origin/<base>..HEAD` then silently includes commits that are already merged, and `git diff origin/<base>...HEAD` fails with "no merge base" — the two commands the prompt tells Claude to run to scope its work to the PR. Gate the flag on `git rev-parse --is-shallow-repository`, so a checkout that is already shallow (the fetch-depth: 1 default) keeps the same depth behaviour and the fetch savings it was added for, while a full checkout stays full. Fixes #1642
This commit is contained in:
@@ -394,6 +394,37 @@ describe("restoreConfigFromBase", () => {
|
||||
expect(countClaudePrExcludeEntries()).toBe(1);
|
||||
});
|
||||
|
||||
test("leaves a full checkout unshallow so base..HEAD stays scoped to the PR", () => {
|
||||
// The damage only shows up once base has moved on since the PR branched:
|
||||
// the merge base is then an older commit that a depth-limited fetch of base
|
||||
// truncates away, and every base..HEAD comparison silently changes meaning.
|
||||
git(["checkout", "main"]);
|
||||
writeRepoFile("src/other.ts", "export const advanced = true;\n");
|
||||
git(["add", "src/other.ts"]);
|
||||
git(["commit", "-m", "base advance"]);
|
||||
git(["push", "origin", "main"]);
|
||||
git(["checkout", "pr"]);
|
||||
|
||||
expect(git(["rev-parse", "--is-shallow-repository"]).trim()).toBe("false");
|
||||
const mergeBaseBefore = git(["merge-base", "origin/main", "HEAD"]).trim();
|
||||
|
||||
restoreConfigFromBase("main");
|
||||
|
||||
expect(git(["rev-parse", "--is-shallow-repository"]).trim()).toBe("false");
|
||||
expect(git(["merge-base", "origin/main", "HEAD"]).trim()).toBe(
|
||||
mergeBaseBefore,
|
||||
);
|
||||
// These are the two commands the prompt tells Claude to run to scope its
|
||||
// work to the PR: the log range must not pick up already-merged commits,
|
||||
// and the three-dot diff must still resolve a merge base at all.
|
||||
expect(git(["log", "--format=%s", "origin/main..HEAD"]).trim()).toBe(
|
||||
"pr config",
|
||||
);
|
||||
expect(
|
||||
git(["diff", "--name-only", "origin/main...HEAD"]).trim().split("\n"),
|
||||
).toEqual([".claude/settings.json", "CLAUDE.md"]);
|
||||
});
|
||||
|
||||
function git(args: string[]): string {
|
||||
return execFileSync("git", args, {
|
||||
cwd: repoDir,
|
||||
|
||||
Reference in New Issue
Block a user