Skip to content

Commit 8150b36

Browse files
committed
NO-JIRA: Handle upstream file deletions gracefully in restore-upstream step
When a file listed in restore-upstream is deleted in upstream, git checkout --theirs fails as there is no upstream version to restore. The step now checks each file's conflict status individually and runs git rm for files deleted upstream (UD) instead of erroring out. Signed-off-by: Jayapriya Pai <janantha@redhat.com>
1 parent ac78325 commit 8150b36

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

.github/workflows/merge-flow.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,19 @@ jobs:
142142
if: ${{ steps.merge.outputs.MERGE_CONFLICT == 'true' && inputs.restore-upstream != ''}}
143143
run: |
144144
echo "reset ${{ inputs.restore-upstream }}"
145-
git checkout --theirs ${{ inputs.restore-upstream }}
146-
git add ${{ inputs.restore-upstream }}
145+
for file in ${{ inputs.restore-upstream }}; do
146+
# Get the two-character porcelain status for this file (e.g. UU, UD, DU)
147+
status=$(git status --porcelain "$file" 2>/dev/null | cut -c1-2 | tr -d ' ')
148+
if [ "$status" == "UD" ]; then
149+
# File was deleted in upstream - remove it from downstream as well
150+
git rm "$file"
151+
elif [ -n "$status" ]; then
152+
# File exists in upstream - restore to upstream (theirs) version
153+
git checkout --theirs "$file"
154+
git add "$file"
155+
fi
156+
# If status is empty the file has no conflict, skip it
157+
done
147158
- name: Resolve conflict using downstream contents
148159
if: ${{ steps.merge.outputs.MERGE_CONFLICT == 'true' && inputs.restore-downstream != ''}}
149160
run: |

0 commit comments

Comments
 (0)