Skip to content

Commit 0a32b3f

Browse files
committed
fix(checkout): use git clone instead of gh repo clone
Root cause: gh repo clone creates incomplete clones where commit objects are missing from the pack file. The refs and .idx files exist, but the actual .pack data is not fully downloaded. This causes "bad object HEAD" and "corrupt patch at line N" errors. Fix: use git clone --depth 1 with HTTPS URL directly. This is more reliable and also avoids the gh-specific syntax issues. Changed: - First clone: 'git clone --depth 1 --branch {branch} -- https://github.com/{repo}.git {path}' - Retry clone: same (already used --depth 1) - Removed both gh repo clone invocations Note: git clone sets up origin remote (unlike gh repo clone), which also enables 'git fetch origin' in the cache sync path. Verification: - php -l: no errors - PHPStan level 8: 0 errors - Worker tests: 75/75 pass - CLI tests: 232/232 pass
1 parent fcae2db commit 0a32b3f

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

scripts/github-code-review.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,14 +1472,15 @@ function checkoutBranch(string $repo, string $branch, string $checkoutPath): str
14721472
cleanupCheckout($checkoutPath);
14731473
}
14741474

1475-
// Use gh repo clone which automatically uses gh authentication
1476-
// Correct syntax: gh repo clone <repository> [<directory>] [-- <gitflags>...]
1477-
// Directory must come BEFORE '--', branch must come AFTER '--'
1475+
// Use git clone directly (not gh repo clone) — gh repo clone creates
1476+
// incomplete clones where commit objects are missing from the pack file,
1477+
// causing "bad object HEAD" and "corrupt patch" errors during apply.
1478+
// We pass --depth 1 for faster clones since we only need the base branch.
14781479
$cloneCmd = sprintf(
1479-
'gh repo clone %s %s -- --branch %s 2>&1',
1480-
escapeshellarg($repo),
1481-
escapeshellarg($checkoutPath),
1482-
escapeshellarg($branch)
1480+
'git clone --depth 1 --branch %s -- %s %s 2>&1',
1481+
escapeshellarg($branch),
1482+
escapeshellarg("https://github.com/{$repo}.git"),
1483+
escapeshellarg($checkoutPath)
14831484
);
14841485

14851486
verbose_log("executing: {$cloneCmd}", 3);
@@ -1521,12 +1522,12 @@ function checkoutBranch(string $repo, string $branch, string $checkoutPath): str
15211522
return 'shutdown';
15221523
}
15231524

1524-
// Try with --depth 1 passed through to git (after --)
1525+
// Try git clone --depth 1 (full clone may have network issues)
15251526
$cloneCmd = sprintf(
1526-
'gh repo clone %s %s -- --depth 1 --branch %s 2>&1',
1527-
escapeshellarg($repo),
1528-
escapeshellarg($checkoutPath),
1529-
escapeshellarg($branch)
1527+
'git clone --depth 1 --branch %s -- %s %s 2>&1',
1528+
escapeshellarg($branch),
1529+
escapeshellarg("https://github.com/{$repo}.git"),
1530+
escapeshellarg($checkoutPath)
15301531
);
15311532
exec($cloneCmd, $cloneOutput, $cloneRet);
15321533

0 commit comments

Comments
 (0)