Skip to content

Commit e20158b

Browse files
committed
INFRA-3187: Code review fix
1 parent 7f9ddf2 commit e20158b

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

.github/scripts/merge-previous-releases.sh

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,36 @@ merge_with_favor_destination() {
8383

8484
echo "⚠️ Merge conflict detected! Resolving by favoring destination branch (new release)..."
8585

86-
# First, resolve any unmerged (conflicted) files by keeping our version
86+
# Resolve any unmerged (conflicted) files by keeping destination version.
87+
#
88+
# Git merge terminology in this context:
89+
# - "ours" = destination branch (new release, e.g., release/2.1.2) - the branch we're ON
90+
# - "theirs" = source branch (older release, e.g., release/2.1.1) - the branch being merged IN
91+
#
92+
# We favor "ours" (destination) because the new release branch should take precedence.
8793
local conflict_files
8894
local conflict_count=0
8995
conflict_files=$(git diff --name-only --diff-filter=U 2>/dev/null || true)
9096
if [[ -n "$conflict_files" ]]; then
9197
while IFS= read -r file; do
9298
if [[ -n "$file" ]]; then
9399
echo " - Conflict in: ${file} → keeping destination version"
94-
git_exec checkout --ours "$file"
95-
git_exec add "$file"
100+
# Try to checkout destination version ("ours")
101+
# If checkout fails, the file was deleted in destination - keep that deletion
102+
if git checkout --ours "$file" 2>/dev/null; then
103+
git add "$file"
104+
else
105+
# Modify/delete conflict scenario:
106+
# - Destination branch (new release) ALREADY deleted this file intentionally
107+
# - Source branch (older release) modified this file
108+
# - Git doesn't know which action to keep
109+
#
110+
# We use "git rm" to confirm the deletion should stand (destination wins).
111+
# This does NOT delete a file that exists - it tells Git "keep the file deleted".
112+
# The --force flag is required because the file is in a conflicted/unmerged state.
113+
echo " (file was deleted in destination, keeping deletion)"
114+
git rm --force "$file" 2>/dev/null || true
115+
fi
96116
((conflict_count++)) || true
97117
fi
98118
done <<< "$conflict_files"

0 commit comments

Comments
 (0)