diff --git a/src/scripts/merge_tools/gitmerge_ort.sh b/src/scripts/merge_tools/gitmerge_ort.sh index d8a695734b..a72d9ee50c 100755 --- a/src/scripts/merge_tools/gitmerge_ort.sh +++ b/src/scripts/merge_tools/gitmerge_ort.sh @@ -7,4 +7,6 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s ort" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if ! "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 1 +fi diff --git a/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh b/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh index ef1a5df5f8..a085edcaa6 100755 --- a/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh @@ -7,4 +7,6 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s ort -Xignore-space-change" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if ! "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 1 +fi diff --git a/src/scripts/merge_tools/gitmerge_ort_imports.sh b/src/scripts/merge_tools/gitmerge_ort_imports.sh index dcd8077ad7..cf0309d91f 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports.sh @@ -7,6 +7,11 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s ort" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 0 +fi -(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts) +cd "$clone_dir" || exit 1 +if ! "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts; then + exit 1 +fi diff --git a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh index 324fdea7e3..b6ae36b948 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh @@ -7,6 +7,11 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s ort -Xignore-space-change" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 0 +fi -(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts) +cd "$clone_dir" || exit 1 +if ! "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts; then + exit 1 +fi diff --git a/src/scripts/merge_tools/gitmerge_recursive_histogram.sh b/src/scripts/merge_tools/gitmerge_recursive_histogram.sh index 6453c6e00e..3d8238775a 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_histogram.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_histogram.sh @@ -7,4 +7,6 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s recursive -Xdiff-algorithm=histogram" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if ! "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 1 +fi diff --git a/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh b/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh index 812d2dcd18..519db73d40 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh @@ -7,4 +7,6 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s recursive -Xignore-space-change" -"$MERGE_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if ! "$MERGE_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 1 +fi diff --git a/src/scripts/merge_tools/gitmerge_recursive_minimal.sh b/src/scripts/merge_tools/gitmerge_recursive_minimal.sh index e7d916539a..e5a6edff9f 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_minimal.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_minimal.sh @@ -7,4 +7,6 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s recursive -Xdiff-algorithm=minimal" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if ! "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 1 +fi diff --git a/src/scripts/merge_tools/gitmerge_recursive_myers.sh b/src/scripts/merge_tools/gitmerge_recursive_myers.sh index f95f093ba7..3fafe5e977 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_myers.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_myers.sh @@ -7,4 +7,6 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s recursive -Xdiff-algorithm=myers" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if ! "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 1 +fi diff --git a/src/scripts/merge_tools/gitmerge_recursive_patience.sh b/src/scripts/merge_tools/gitmerge_recursive_patience.sh index 77e5a8e449..ef47dc2cab 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_patience.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_patience.sh @@ -7,4 +7,6 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s recursive -Xdiff-algorithm=patience" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if ! "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then + exit 1 +fi diff --git a/src/scripts/merge_tools/resolve-import-conflicts b/src/scripts/merge_tools/resolve-import-conflicts index 4b311eddc3..fc4605f54a 100755 --- a/src/scripts/merge_tools/resolve-import-conflicts +++ b/src/scripts/merge_tools/resolve-import-conflicts @@ -9,6 +9,10 @@ # 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 conflicts remain after running this script or if +# there is an error generated in some file. +# Exit status is 0 if there are no conflicts after running this script. + if [ "$#" -eq 0 ] ; then readarray -t files < <(grep -l -r '^<<<<<<< HEAD' .) else @@ -17,12 +21,20 @@ fi SCRIPTDIR="$(cd "$(dirname "$0")" && pwd -P)" -status=0 - for file in "${files[@]}" ; do if ! "${SCRIPTDIR}"/resolve-import-conflicts-in-file.py "$file" ; then - status=1 + echo "Error in $file" + git merge --abort + exit 1 fi done -exit $status +# From https://stackoverflow.com/questions/41246415/ +if git diff --exit-code -S '<<<<<<< HEAD' -S "=======" -S ">>>>>>> $(git name-rev --name-only MERGE_HEAD)" HEAD ; then + exit 0 +fi + +echo "Conflict" +git merge --abort +exit 1 + 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. """