Skip to content

Commit 81cb3e3

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

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

scripts/sync_pop_candidate.sh

Lines changed: 34 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,44 @@ 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+
# Note: this may require a more up-to-date git version
38+
if ! git cherry-pick --allow-empty --keep-redundant-commits -Xsubtree="${subtree_dir}" "${rc}"; then
39+
# Always blast away the vendor directory given OLM/registry still commit it into source control.
40+
git rm -rf "${subtree_dir}"/vendor 2>/dev/null || true
41+
42+
# TODO: handle the case where there's a single merge conflict.
43+
# TODO: handle root go.mod merge conflicts!
44+
# TODO: maybe use a while loop here?
45+
# TODO: verify there's no remaining merge conflicts
46+
num_conflicts=$(git diff --name-only --diff-filter=U --relative | wc -l)
47+
while [[ $num_conflicts != 0 ]] ; do
48+
file=$(git diff --name-only --diff-filter=U --relative)
49+
50+
if [[ $file == *"go.mod"* ]]; then
51+
git diff "${subtree_dir}"/go.mod
52+
53+
git checkout --theirs "${subtree_dir}"/go.mod
54+
pushd "${subtree_dir}"
55+
# Note: handle case where this fails. does this update the root module too?
56+
go mod tidy
57+
# TODO: double-check there's no remaining markers via git diff --check: <https://stackoverflow.com/questions/3065650/whats-the-simplest-way-to-list-conflicted-files-in-git>?
58+
git add go.mod go.sum
59+
popd
60+
else
61+
git checkout --theirs "$file"
62+
git diff "$file"
63+
git add "$file"
64+
fi
65+
66+
num_conflicts=$(git diff --name-only --diff-filter=U --relative | wc -l)
67+
echo "number of merge conflicts remaining: $num_conflicts"
68+
done
4869

4970
if [[ -z $(git status --porcelain) ]]; then
5071
git commit --allow-empty
5172
else
52-
git cherry-pick --continue
73+
echo "Current cherry pick status: $(git status --porcelain)"
74+
git -c core.editor=true cherry-pick --continue
5375
fi
5476
fi
5577

0 commit comments

Comments
 (0)