Skip to content

Commit 8a80bf9

Browse files
committed
scripts: Add logic for handling common merge conflicts
Signed-off-by: timflannagan <[email protected]>
1 parent 4cf97b0 commit 8a80bf9

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

scripts/sync_pop_candidate.sh

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
cph=$(git rev-list -n 1 CHERRY_PICK_HEAD 2> /dev/null)
4-
53
set -o errexit
64
set -o pipefail
75

@@ -36,20 +34,37 @@ function pop() {
3634
fi
3735
printf 'popping: %s\n' "${rc}"
3836

39-
if [[ ! $cph ]]; then
40-
git cherry-pick --allow-empty --keep-redundant-commits -Xsubtree="${subtree_dir}" "${rc}"
41-
else
42-
if [[ $cph != "${rc}" ]]; then
43-
printf 'unexpected CHERRY_PICK_HEAD:\ngot %s\nexpected: %s\n' "${cph}" "${rc}"
44-
exit
45-
fi
46-
printf 'cherry-pick in progress for %s\n' "${cph}"
47-
git add .
37+
if ! git cherry-pick --allow-empty --keep-redundant-commits -Xsubtree="${subtree_dir}" "${rc}"; then
38+
# Always blast away the vendor directory given OLM/registry still commit it into source control.
39+
git rm -rf "${subtree_dir}"/vendor 2>/dev/null || true
40+
41+
num_conflicts=$(git diff --name-only --diff-filter=U --relative | wc -l)
42+
while [[ $num_conflicts != 0 ]] ; do
43+
file=$(git diff --name-only --diff-filter=U --relative)
44+
45+
if [[ $file == *"go.mod"* ]]; then
46+
git diff "${subtree_dir}"/go.mod
47+
48+
git checkout --theirs "${subtree_dir}"/go.mod
49+
pushd "${subtree_dir}"
50+
go mod tidy
51+
git add go.mod go.sum
52+
popd
53+
else
54+
git checkout --theirs "$file"
55+
git diff "$file"
56+
git add "$file"
57+
fi
58+
59+
num_conflicts=$(git diff --name-only --diff-filter=U --relative | wc -l)
60+
echo "Number of merge conflicts remaining: $num_conflicts"
61+
done
4862

4963
if [[ -z $(git status --porcelain) ]]; then
5064
git commit --allow-empty
5165
else
52-
git cherry-pick --continue
66+
echo "Current cherry pick status: $(git status --porcelain)"
67+
git -c core.editor=true cherry-pick --continue
5368
fi
5469
fi
5570

0 commit comments

Comments
 (0)