Skip to content

Commit 9aa02ee

Browse files
Fix git checkout error by using commit hash instead of ref
The workflow was failing with "pathspec 'refs/pull/170/merge' did not match any file(s)" because: - GitHub Actions passes ${{ github.ref }} which is 'refs/pull/170/merge' for PRs - This is a GitHub-specific reference that exists remotely but can't be checked out as a local branch - After pushing to pr-screenshot branch, script tried to checkout this ref and failed Fixed by: - Saving the current commit hash (git rev-parse HEAD) before switching branches - Using that commit hash to return to the original state (works in detached HEAD mode) - This approach works regardless of whether we're on a branch, tag, or PR merge ref The workflow will now: 1. Save current commit hash 2. Switch to pr-screenshot branch and push screenshots 3. Return to the saved commit hash (detached HEAD is fine in CI) 4. Continue with subsequent workflow steps that check for changes and comment on PR Co-authored-by: richardthe3rd <573334+richardthe3rd@users.noreply.github.com>
1 parent fb369b0 commit 9aa02ee

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

scripts/update_screenshot_branch.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ echo "Source branch: $SOURCE_BRANCH"
2626
# Store the current directory to return to it
2727
ORIGINAL_DIR=$(pwd)
2828

29+
# Store the current commit hash to return to it later
30+
ORIGINAL_COMMIT=$(git rev-parse HEAD)
31+
2932
# Copy screenshots to a temp directory BEFORE switching branches
3033
TEMP_DIR=$(mktemp -d)
3134
echo "Copying screenshots to temporary directory: $TEMP_DIR"
@@ -109,6 +112,7 @@ else
109112
echo "✓ Screenshots updated successfully to $BRANCH_NAME/$PR_FOLDER"
110113
fi
111114

112-
# Return to the original branch
113-
echo "Returning to source branch: $SOURCE_BRANCH..."
114-
git checkout "$SOURCE_BRANCH"
115+
# Return to the original commit
116+
# Use the commit hash we saved earlier, which works regardless of branch/ref type
117+
echo "Returning to original commit: $ORIGINAL_COMMIT..."
118+
git checkout "$ORIGINAL_COMMIT"

0 commit comments

Comments
 (0)