anthropics / anthropics/claude-code-action

Git safe.directory error when running in container job

Đang mở
#161 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
bug p1
Ngôn ngữ chính
TypeScript
Star
8.9k
Fork
2.1k
Merge trung bình
3 ngày 9 giờ
Pull request đã merge (30 ngày)
10

Mô tả

**Describe the bug**
When claude-code-action is run in a [container job](https://docs.github.com/en/actions/writing-workflows/choosing-where-your-workflow-runs/running-jobs-in-a-container), it throws the following error:

```console
Run bun run ${GITHUB_ACTION_PATH}/src/entrypoints/prepare.ts
...
Successfully fetched PR #115633 data
This is an open PR, checking out PR branch...
fatal: detected dubious ownership in repository at '/__w/example/example'
To add an exception for this directory, call:

git config --global --add safe.directory /__w/example/example
Error: Prepare step failed with error: Failed with exit code 128
Error: Process completed with exit code 1.
```

**To Reproduce**
Here is a snippet of the workflow to reproduce this issue.

```yaml
jobs:
claude-code-action:
runs-on: ubuntu-latest
container:
image: # Our custom image
options: --user root
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@beta
with:
# Omit...
```

**Expected behavior**
The git command successfully finish.

For a workaround, just setting `safe.directory` config resolves this issue.

```yaml
steps:
- run: git config --global --add safe.directory /__w/example/example # <-- Set your repository name
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@beta
```

**API Provider**
Not related to this issue.

**Additional context**
For actions/checkout, it sets `safe.directory` config temporarily to avoid this issue.
https://github.com/actions/checkout/blob/09d2acae674a48949e3602304ab46fd20ae0c42f/src/git-source-provider.ts#L46-L60

I'm not sure about the security concern of `safe.directory` config, but let me share a workaround.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.