Skip to content

Commit 608e809

Browse files
authored
Fix: Resolve git checkout error in fetch-sfs-workflow (#55)
## Problem The `fetch-sfs-workflow` was failing with this error: ``` error: Your local changes to the following files would be overwritten by checkout: data/md-markers/... Aborting ``` ## Root Cause The workflow was staging changes with `git add` **before** attempting to checkout the target branch. When the branch existed remotely, `git checkout` would fail because it would overwrite the staged changes. ## Solution This PR fixes the issue by: 1. Checking for changes **without** staging them first (using `git diff --quiet` and `git ls-files --others`) 2. Checking out the target branch **before** running `git add` 3. Staging files only after being on the correct branch ## Testing The workflow should now successfully: - Check for changes in `data/md-markers/` and `data/sfs_json/` - Checkout existing `workflow-artifact-data` branch without conflicts - Stage and commit changes on the correct branch ## Related Fixes the error seen in: https://github.com/se-lex/sfs-processor/actions/runs/20804696587/job/59756444556 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent c9b5da1 commit 608e809

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

.github/workflows/fetch-sfs-workflow.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ jobs:
8888
# Get current branch
8989
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
9090
91-
# Create a new branch for commits if we have changes
92-
git add data/md-markers/ data/sfs_json/
93-
if git diff --staged --quiet; then
91+
# Check if we have changes (without staging yet)
92+
if git diff --quiet data/md-markers/ data/sfs_json/ && \
93+
! git ls-files --others --exclude-standard data/md-markers/ data/sfs_json/ | grep -q .; then
9494
echo "Inga nya filer att committa"
9595
echo "has_changes=false" >> $GITHUB_OUTPUT
9696
else
@@ -111,6 +111,9 @@ jobs:
111111
git checkout -b "$COMMIT_BRANCH"
112112
fi
113113
114+
# Now add files after we're on the correct branch
115+
git add data/md-markers/ data/sfs_json/
116+
114117
# Commit with multi-line message
115118
git commit -m "Automatisk uppdatering av SFS-författningar $(date +'%Y-%m-%d')" \
116119
-m "" \

0 commit comments

Comments
 (0)