From bed5a0337c0aa06763e7b5ae3865c70e222076f1 Mon Sep 17 00:00:00 2001 From: hudeng Date: Wed, 29 Jul 2026 10:29:07 +0800 Subject: [PATCH] fix: use branch ref instead of SHA for actions/checkout@v7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using a bare SHA as the ref parameter in actions/checkout@v7 causes the getRefSpec function to only fetch the specific commit instead of the full branch. This is problematic when git commit --amend is used on a PR branch, because the amended commit's SHA is not present in the initial fetch, and testRef() always returns true for SHA refs (never triggering the second targeted fetch). The fix is to use refs/heads/ instead of the bare SHA, which makes getRefSpecForAllHistory properly handle the ref and allows testRef() to correctly detect when a force-push has moved the branch. Log: 修复 actions/checkout@v7 在 git commit --amend 后无法正确获取 PR 分支最新 commit 的问题 --- .github/workflows/cppcheck.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cppcheck.yml b/.github/workflows/cppcheck.yml index 85544fae..5ae77f4a 100644 --- a/.github/workflows/cppcheck.yml +++ b/.github/workflows/cppcheck.yml @@ -16,7 +16,7 @@ jobs: - run: export - uses: actions/checkout@v7 with: - ref: ${{ github.event.pull_request.head.sha }} + ref: refs/heads/${{ github.head_ref }} persist-credentials: false allow-unsafe-pr-checkout: true - uses: linuxdeepin/action-cppcheck@main