@@ -104,18 +104,36 @@ jobs:
104104 sync_branch="sync-main-to-${{ matrix.target_branch }}-$(date +%Y%m%d-%H%M%S)"
105105 git checkout -b "$sync_branch" ${{ matrix.target_branch }}
106106
107- # Get ALL commits that need to be applied (including merge commits)
108- # First, get the merge base to ensure we have the correct starting point
109- merge_base=$(git merge-base ${{ matrix.target_branch }} main)
110- echo "📍 Merge base: $merge_base"
107+ # Get only commits from the current push event (not all commits between branches)
108+ # Use the push event data to get commits from this specific push
109+ echo "📍 Getting commits from current push event..."
111110
112- # Get all commits in main that are not in target branch (including merges)
113- # Store commits in a temp file to avoid subshell issues
114- git log "$merge_base..main" --format="%H" --reverse > /tmp/commits_to_apply.txt
111+ # Get commits from the push event
112+ if [ "${{ github.event_name }}" = "push" ] && [ -n "${{ github.event.before }}" ] && [ -n "${{ github.event.after }}" ]; then
113+ # Push event: get commits between before and after
114+ echo "📋 Getting commits from push: ${{ github.event.before }}..${{ github.event.after }}"
115+ git log "${{ github.event.before }}..${{ github.event.after }}" --format="%H" --reverse > /tmp/commits_to_apply.txt
116+ elif [ "${{ github.event_name }}" = "push" ] && [ -n "${{ github.event.head_commit.id }}" ]; then
117+ # Fallback: use head commit if before/after not available
118+ echo "📋 Using head commit: ${{ github.event.head_commit.id }}"
119+ echo "${{ github.event.head_commit.id }}" > /tmp/commits_to_apply.txt
120+ elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
121+ # Manual dispatch: get commits since last sync (merge base to main)
122+ echo "📋 Workflow dispatch: getting commits since last sync"
123+ merge_base=$(git merge-base ${{ matrix.target_branch }} main)
124+ git log "$merge_base..main" --format="%H" --reverse > /tmp/commits_to_apply.txt
125+ else
126+ # Fallback: get commits since merge base
127+ echo "📋 Fallback: getting commits since merge base"
128+ merge_base=$(git merge-base ${{ matrix.target_branch }} main)
129+ git log "$merge_base..main" --format="%H" --reverse > /tmp/commits_to_apply.txt
130+ fi
115131
116- # Also get commits using the simpler range (as fallback)
132+ # If no commits found, try alternative method
117133 if [ ! -s /tmp/commits_to_apply.txt ]; then
118- git log "${{ matrix.target_branch }}..main" --format="%H" --reverse > /tmp/commits_to_apply.txt
134+ echo "⚠️ No commits found with primary method, trying alternative..."
135+ merge_base=$(git merge-base ${{ matrix.target_branch }} main)
136+ git log "$merge_base..main" --format="%H" --reverse > /tmp/commits_to_apply.txt
119137 fi
120138
121139 if [ -s /tmp/commits_to_apply.txt ]; then
0 commit comments