@@ -132,47 +132,83 @@ jobs:
132132
133133 successful_count=0
134134 failed_count=0
135- ignored_count=0
136135 already_applied_count=0
137- # Track ignored commits in array (no file needed)
138- declare -a ignored_commits_array=()
136+
137+ # Use git cherry to find commits that are already in target branch (compares patches, not just hashes)
138+ # This detects commits even if they were cherry-picked with different hashes
139+ # git cherry upstream head: compares 'head' against 'upstream'
140+ # - means commit in 'head' is equivalent to one in 'upstream' (already applied)
141+ # + means commit in 'head' is not in 'upstream' (needs to be applied)
142+ echo "🔍 Checking which commits are already applied (using patch comparison)..."
143+
144+ # Ensure we have the latest state of both branches
145+ git fetch origin ${{ matrix.target_branch }}:refs/remotes/origin/${{ matrix.target_branch }} 2>/dev/null || true
146+ git fetch origin main:refs/remotes/origin/main 2>/dev/null || true
147+
148+ # Get cherry output - this shows commits in 'main' compared to 'target_branch'
149+ # Lines starting with '-' mean the commit in main is equivalent to one already in target_branch
150+ cherry_output=$(git cherry ${{ matrix.target_branch }} main 2>/dev/null || echo "")
151+
152+ # Create a set of commits that are already in target branch (lines starting with '-')
153+ declare -A already_applied_commits=()
154+ if [ -n "$cherry_output" ]; then
155+ echo "📊 Git cherry found $(echo "$cherry_output" | wc -l) commits to check"
156+ while IFS= read -r line; do
157+ if [[ $line =~ ^- ]]; then
158+ # Extract commit hash (second field after the '-' and space)
159+ commit_hash=$(echo "$line" | awk '{print $2}')
160+ if [ -n "$commit_hash" ]; then
161+ already_applied_commits["$commit_hash"]=1
162+ echo " ✓ Commit $commit_hash already applied (patch equivalent)"
163+ fi
164+ fi
165+ done <<< "$cherry_output"
166+ echo "📊 Found ${#already_applied_commits[@]} commits already applied via patch comparison"
167+ fi
139168
140169 # Cherry-pick each commit individually, but first check if it's already in target branch
170+ # Only use git-based detection, no commit message checks
141171 while read commit; do
142- commit_msg=$(git log -1 --format="%s" "$commit")
143- commit_full_msg=$(git log -1 --format="%B" "$commit")
172+ commit_msg=$(git log -1 --format="%s" "$commit" 2>/dev/null || echo "unknown")
144173
145- # Check if commit is already in target branch
174+ # Check if commit is already in target branch (by exact hash)
146175 if git branch --contains "$commit" | grep -q "${{ matrix.target_branch }}"; then
147- echo "⏭️ Commit $commit already in ${{ matrix.target_branch }}, skipping: $commit_msg "
176+ echo "⏭️ Commit $commit already in ${{ matrix.target_branch }} (exact match) , skipping"
148177 already_applied_count=$((already_applied_count + 1))
149178 continue
150179 fi
151180
152- # Check if commit should be ignored (check for ignore patterns in commit message)
153- # Patterns: [skip-sync], [no-sync], [ignore-sync], [skip-branch-sync]
154- if echo "$commit_msg" | grep -qiE '\[(skip-sync|no-sync|ignore-sync|skip-branch-sync)\]' || \
155- echo "$commit_full_msg" | grep -qiE '\[(skip-sync|no-sync|ignore-sync|skip-branch-sync)\]'; then
156- echo "⏭️ Skipping ignored commit $commit: $commit_msg"
157- ignored_commits_array+=("$commit")
158- ignored_count=$((ignored_count + 1))
181+ # Check if commit is already applied (by patch comparison using git cherry)
182+ # This detects commits even if they were cherry-picked with different hashes
183+ if [[ -n "${already_applied_commits[$commit]}" ]]; then
184+ echo "⏭️ Commit $commit already in ${{ matrix.target_branch }} (patch match), skipping"
185+ already_applied_count=$((already_applied_count + 1))
159186 continue
160187 fi
161188
189+ # Commit is new and not already applied, add to filtered list
162190 echo "$commit" >> "$filtered_commits_file"
163191 done < /tmp/commits_to_apply.txt
164192
165193 # Now cherry-pick only the filtered commits
166194 if [ -s "$filtered_commits_file" ]; then
167- echo "🍒 Processing commits (skipped ${already_applied_count} already in branch, ${ignored_count} ignored )..."
195+ echo "🍒 Processing commits (skipped ${already_applied_count} already in branch)..."
168196 while read commit; do
169197 commit_msg=$(git log -1 --format="%s" "$commit")
170198 echo "🍒 Cherry-picking $commit: $commit_msg"
171199
172200 # Try cherry-pick with conflict resolution
173201 if git cherry-pick --no-commit "$commit" 2>&1; then
174- echo "✅ Cherry-pick successful for $commit"
175- successful_count=$((successful_count + 1))
202+ # Check if cherry-pick resulted in actual changes
203+ if git diff --cached --quiet && git diff --quiet; then
204+ # Empty commit, already applied
205+ echo "ℹ️ Commit $commit already applied (no changes), skipping..."
206+ git cherry-pick --abort || true
207+ already_applied_count=$((already_applied_count + 1))
208+ else
209+ echo "✅ Cherry-pick successful for $commit"
210+ successful_count=$((successful_count + 1))
211+ fi
176212 else
177213 # Check if it's already applied (empty commit)
178214 if git diff --cached --quiet && git diff --quiet; then
@@ -189,19 +225,10 @@ jobs:
189225 fi
190226 done < "$filtered_commits_file"
191227 else
192- echo "ℹ️ No new commits to cherry-pick (all commits already in branch or ignored )"
228+ echo "ℹ️ No new commits to cherry-pick (all commits already in branch)"
193229 fi
194230
195- echo "📊 Summary: $successful_count successful cherry-picks, $failed_count failed, $already_applied_count already in branch, $ignored_count ignored"
196-
197- # Show ignored commits if any
198- if [ ${#ignored_commits_array[@]} -gt 0 ]; then
199- echo "⏭️ Ignored commits (marked with [skip-sync], [no-sync], [ignore-sync], or [skip-branch-sync]):"
200- for commit in "${ignored_commits_array[@]}"; do
201- commit_msg=$(git log -1 --format="%s" "$commit" 2>/dev/null || echo "unknown")
202- echo " - $commit: $commit_msg"
203- done
204- fi
231+ echo "📊 Summary: $successful_count successful cherry-picks, $failed_count failed, $already_applied_count already in branch"
205232 else
206233 # No commits found to apply
207234 echo "ℹ️ No commits found to apply - branches may already be in sync"
@@ -333,7 +360,7 @@ jobs:
333360 - ✅ Updated version numbers (10.x.x → ${dotnet_version}.x.x)
334361 - ✅ Updated target framework (net10.0 → net${dotnet_version}.0)
335362 - ✅ Preserved .csproj files from ${{ matrix.target_branch }} branch
336- - ⏭️ Commits marked with \`[skip-sync]\`, \`[no-sync]\`, \`[ignore-sync]\`, or \`[skip- branch-sync]\` were excluded
363+ - ⏭️ Commits already in target branch were automatically excluded
337364
338365 ### Review Notes:
339366 - All .csproj files maintain ${{ matrix.target_branch }} configurations
0 commit comments