diff --git a/src/scripts/merge_tools/gitmerge.sh b/src/scripts/merge_tools/gitmerge.sh index 1c2032d58a..4b6a0b987f 100755 --- a/src/scripts/merge_tools/gitmerge.sh +++ b/src/scripts/merge_tools/gitmerge.sh @@ -1,16 +1,19 @@ #!/usr/bin/env sh -# usage: ./gitmerge.sh +# usage: ./gitmerge.sh [no-git-merge-abort] # must contain a clone of a repository. # is arguments to `git merge`, including -s and possibly -X. # Merges branch2 into branch1, in , using merge strategy . -# Return code is 0 for merge success, 1 for merge failure. -# For merge failure, also outputs "Conflict" and aborts the merge. +# For merge success, return code is 0. +# For merge failure: +# * return code is 1. +# * outputs "Conflict". +# * aborts the merge, unless a 5th command-line argument is provided. set -o nounset -if [ "$#" -ne 4 ]; then - echo "Usage: $0 CLONE_DIR BRANCH1 BRANCH2 STRATEGY" >&2 +if [ "$#" -ne 4 ] && [ "$#" -ne 5 ]; then + echo "Usage: $0 CLONE_DIR BRANCH1 BRANCH2 STRATEGY [no-git-merge-abort]" >&2 exit 1 fi @@ -18,6 +21,8 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy=$4 +# If this variable is non-empty, don't run `git merge --abort`. +no_git_merge_abort=$5 # perform merge cd "$clone_dir" || exit 1 @@ -30,7 +35,9 @@ retVal=$? # report conflicts if [ $retVal -ne 0 ]; then echo "Conflict" - git merge --abort + if [ -z "$no_git_merge_abort" ] ; then + git merge --abort + fi fi exit $retVal diff --git a/src/scripts/merge_tools/gitmerge_ort_imports.sh b/src/scripts/merge_tools/gitmerge_ort_imports.sh index 221280a6e0..44145e89d5 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports.sh @@ -7,6 +7,16 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s ort" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" "no-git-merge-abort" +status=$? -(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts) +if ! "$status" ; then + (cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts) + + # From https://stackoverflow.com/questions/41246415/ + status=$(git diff --exit-code -S '<<<<<<< HEAD' -S "=======" -S ">>>>>>> $(git name-rev --name-only MERGE_HEAD)" HEAD) + + git merge --abort +fi + +exit "$status" diff --git a/src/scripts/merge_tools/resolve-import-conflicts b/src/scripts/merge_tools/resolve-import-conflicts index feaee8b83c..9778647846 100755 --- a/src/scripts/merge_tools/resolve-import-conflicts +++ b/src/scripts/merge_tools/resolve-import-conflicts @@ -8,6 +8,9 @@ # parent 2 files, all without conflict markers. # However, this script can be run instead of a git mergetool, or after a git mergetool. +# Exit status is 1 if merging some file halted exceptionally. +# With an exit status of 0, some conflicts may still exist in the current repository. + if [ "$#" -eq 0 ] ; then readarray -t files < <(grep -l -r '^<<<<<<< HEAD' .) else diff --git a/src/scripts/merge_tools/resolve-import-conflicts-in-file.py b/src/scripts/merge_tools/resolve-import-conflicts-in-file.py index 9c4f7878c0..2398ec4586 100755 --- a/src/scripts/merge_tools/resolve-import-conflicts-in-file.py +++ b/src/scripts/merge_tools/resolve-import-conflicts-in-file.py @@ -1,7 +1,11 @@ #! /usr/bin/env python """Edits a file in place to remove conflict markers related to Java imports. -It simplistically leaves all the imports that appear in either parent. +The merged version contains all the imports that appear in either parent. +This is simplistic, but is often adequate. + +Exit status is 1 only if the program halts exceptionally. +With an exit status of 0, some conflicts may still exist in the file. """