@@ -44,24 +44,50 @@ jobs:
4444 env :
4545 TOKEN : ${{ secrets.GITHUB_TOKEN }}
4646 run : |
47- git fetch origin
48- git checkout ${{ github.head_ref }}
49- git pull origin ${{ github.head_ref }} || echo "No merge needed"
50- git add -A
51- git commit -m "Update visitor count" || echo "No changes to commit"
47+ BRANCH="${{ github.head_ref }}"
5248 git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
53- git push origin HEAD:${{ github.head_ref }}
49+ HAS_CHANGES=false
50+ if ! git diff --quiet || ! git diff --cached --quiet || [ -n "$(git ls-files --others --exclude-standard)" ]; then
51+ HAS_CHANGES=true
52+ git stash push --include-untracked --message visitor-counter
53+ fi
54+ git fetch origin "$BRANCH"
55+ git checkout -B "$BRANCH" "origin/$BRANCH"
56+ if [ "$HAS_CHANGES" = true ]; then
57+ git stash pop
58+ fi
59+ git add -A
60+ if git diff --cached --quiet; then
61+ echo "No changes to commit"
62+ exit 0
63+ fi
64+ git commit -m "Update visitor count"
65+ git pull --rebase origin "$BRANCH"
66+ git push origin HEAD:"$BRANCH"
5467
5568 # Commit and push logic for non-PR events (merge, not rebase)
5669 - name : Commit and push changes (non-PR)
5770 if : github.event_name != 'pull_request'
5871 env :
5972 TOKEN : ${{ secrets.GITHUB_TOKEN }}
6073 run : |
61- git fetch origin
62- git checkout ${{ github.ref_name }} || git checkout -b ${{ github.ref_name }} origin/${{ github.ref_name }}
63- git pull origin ${{ github.ref_name }} || echo "No merge needed"
64- git add -A
65- git commit -m "Update visitor count" || echo "No changes to commit"
74+ BRANCH="${{ github.ref_name }}"
6675 git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
67- git push origin HEAD:${{ github.ref_name }}
76+ HAS_CHANGES=false
77+ if ! git diff --quiet || ! git diff --cached --quiet || [ -n "$(git ls-files --others --exclude-standard)" ]; then
78+ HAS_CHANGES=true
79+ git stash push --include-untracked --message visitor-counter
80+ fi
81+ git fetch origin "$BRANCH"
82+ git checkout -B "$BRANCH" "origin/$BRANCH"
83+ if [ "$HAS_CHANGES" = true ]; then
84+ git stash pop
85+ fi
86+ git add -A
87+ if git diff --cached --quiet; then
88+ echo "No changes to commit"
89+ exit 0
90+ fi
91+ git commit -m "Update visitor count"
92+ git pull --rebase origin "$BRANCH"
93+ git push origin HEAD:"$BRANCH"
0 commit comments