|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -cph=$(git rev-list -n 1 CHERRY_PICK_HEAD 2> /dev/null) |
4 |
| - |
5 | 3 | set -o errexit
|
6 | 4 | set -o pipefail
|
7 | 5 |
|
@@ -36,20 +34,44 @@ function pop() {
|
36 | 34 | fi
|
37 | 35 | printf 'popping: %s\n' "${rc}"
|
38 | 36 |
|
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 |
48 | 69 |
|
49 | 70 | if [[ -z $(git status --porcelain) ]]; then
|
50 | 71 | git commit --allow-empty
|
51 | 72 | else
|
52 |
| - git cherry-pick --continue |
| 73 | + echo "Current cherry pick status: $(git status --porcelain)" |
| 74 | + git -c core.editor=true cherry-pick --continue |
53 | 75 | fi
|
54 | 76 | fi
|
55 | 77 |
|
|
0 commit comments