anthropics / anthropics/claude-code-action

Title: [BUG] Action fails with "git hash-object" error when PR deletes files

Aperta
#730 1 commento 3 reazioni 0 assegnatari Vedi su GitHub
area:installation bug p1
Lingua principale
TypeScript
Stelle
8.9k
Fork
2.1k
Merge medio
3g 9h
PR unite (30g)
10

Descrizione

Describe the bug
The claude-code-action@v1 fails during the prepare step when a PR deletes or renames files. The action attempts to compute SHA hashes for all files in the PR diff using git hash-object, but this fails for deleted/renamed files because they don't exist on the PR branch.
To Reproduce

Create a PR that deletes or renames files
Trigger the claude-code-action via @claude mention or automatic PR review
Action fails with fatal: could not open '' for reading: No such file or directory

Error Log
fatal: could not open 'approval_service/backend/approval_django/approval/api/views/receive_task.py' for reading: No such file or directory
Failed to compute SHA for approval_service/backend/approval_django/approval/api/views/receive_task.py: warn: Command failed: git hash-object approval_service/backend/approval_django/approval/api/views/receive_task.py
fatal: could not open 'approval_service/backend/approval_django/approval/api/views/receive_task.py' for reading: No such file or directory

signal: null,
status: 128,
output: [
null, "", "fatal: could not open '...' for reading: No such file or directory\n"
],

at genericNodeError (node:child_process:941:13)
at checkExecSyncError (node:child_process:449:27)
at execFileSync (node:child_process:268:31)
at (/home/runner/work/_actions/anthropics/claude-code-action/v1/src/github/data/fetcher.ts:251:21)
at map (1:11)
at fetchGitHubData (/home/runner/work/_actions/anthropics/claude-code-action/v1/src/github/data/fetcher.ts:240:40)
This error repeats for each deleted file in the PR (12+ times in PR #31). The action then fails with:
This is an open PR, checking out PR branch...
PR #31: 3 commits, using fetch depth 20
fatal: not a git repository (or any of the parent directories): .git
Error: Prepare step failed with error: Failed with exit code 128
Error: Process completed with exit code 1.
Expected behavior
The action should handle deleted/renamed files gracefully by:

Skipping SHA computation for files that were deleted in the PR
Checking the file's diff status before attempting git hash-object
Or wrapping the git hash-object call in a try-catch that handles missing files

Root Cause Analysis
The issue is in src/github/data/fetcher.ts around line 240-251. The code iterates over all files in the PR diff and runs git hash-object on each one, but doesn't account for files with status removed or renamed.
Suggested Fix
typescript// In fetcher.ts around line 240-251
// Check file status before computing SHA
if (file.status === 'removed') {
// Skip deleted files - they don't exist on the PR branch
continue;
}

// For renamed files, use the new filename
const filename = file.status === 'renamed' ? file.filename : file.filename;

// Wrap in try-catch as safety net
try {
const sha = execFileSync('git', ['hash-object', filename]);
} catch (err) {
// File doesn't exist, skip SHA computation
console.warn(`Skipping SHA for missing file: ${filename}`);
}
Environment

Action version: anthropics/claude-code-action@v1
Runner: ubuntu-latest
Event: issue_comment (triggered by @claude mention on PR)
Bun version: 1.2.11

Workaround
Currently none known. PRs that delete files cannot use claude-code-action until this is fixed.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.