diff --git a/src/scripts/merge_tools/git_hires_merge.sh b/src/scripts/merge_tools/git_hires_merge.sh index b1912eb703..a463e936b0 100755 --- a/src/scripts/merge_tools/git_hires_merge.sh +++ b/src/scripts/merge_tools/git_hires_merge.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -# usage: ./git-hires-merge.sh +# usage: ./git_hires_merge.sh clone_dir=$1 branch1=$2 diff --git a/src/scripts/merge_tools/gitmerge.sh b/src/scripts/merge_tools/gitmerge.sh index 4b6a0b987f..bbf3e293f2 100755 --- a/src/scripts/merge_tools/gitmerge.sh +++ b/src/scripts/merge_tools/gitmerge.sh @@ -7,8 +7,8 @@ # 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. +# * outputs "Conflict" and aborts the merge, +# unless a non-empty 5th command-line argument is provided. set -o nounset @@ -21,7 +21,7 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy=$4 -# If this variable is non-empty, don't run `git merge --abort`. +# If this variable is non-empty, don't output "Conflict" or run `git merge --abort`. no_git_merge_abort=$5 # perform merge @@ -34,8 +34,8 @@ retVal=$? # report conflicts if [ $retVal -ne 0 ]; then - echo "Conflict" if [ -z "$no_git_merge_abort" ] ; then + echo "Conflict" git merge --abort fi fi diff --git a/src/scripts/merge_tools/gitmerge_ort.sh b/src/scripts/merge_tools/gitmerge_ort.sh index 51947da10e..d8a695734b 100755 --- a/src/scripts/merge_tools/gitmerge_ort.sh +++ b/src/scripts/merge_tools/gitmerge_ort.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -# usage: ./gitmerge-ort.sh +# usage: ./gitmerge_ort.sh MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 diff --git a/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh b/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh index 2a40212493..ef1a5df5f8 100755 --- a/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -# usage: ./gitmerge-ort-ignorespace.sh +# usage: ./gitmerge_ort_ignorespace.sh MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 diff --git a/src/scripts/merge_tools/gitmerge_ort_imports.sh b/src/scripts/merge_tools/gitmerge_ort_imports.sh index 44145e89d5..91d199fd90 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports.sh @@ -1,22 +1,14 @@ #!/usr/bin/env sh -# usage: ./gitmerge-ort.sh +# usage: ./gitmerge_ort_imports.sh MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 branch1=$2 branch2=$3 strategy="-s ort" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" "no-git-merge-abort" -status=$? - -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 +if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" "no-git-merge-abort" ; then + exit fi -exit "$status" +(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts-or-abort-merge) diff --git a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh index 03770b22f7..bfd82af44b 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh @@ -1,12 +1,14 @@ #!/usr/bin/env sh -# usage: ./gitmerge-ort-ignorespace.sh +# usage: ./gitmerge_ort_imports_ignorespace.sh MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" 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" "no-git-merge-abort" ; then + exit +fi -(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts) +(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts-or-abort-merge) diff --git a/src/scripts/merge_tools/gitmerge_recursive_histogram.sh b/src/scripts/merge_tools/gitmerge_recursive_histogram.sh index 8e239dd933..6453c6e00e 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_histogram.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_histogram.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -# usage: ./gitmerge-recursive-histogram.sh +# usage: ./gitmerge_recursive_histogram.sh MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 diff --git a/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh b/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh index 3535ace430..812d2dcd18 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -# usage: ./gitmerge-recursive-histogram.sh +# usage: ./gitmerge_recursive_ignorespace.sh MERGE_DIR="$(dirname "$0")" clone_dir=$1 diff --git a/src/scripts/merge_tools/gitmerge_recursive_minimal.sh b/src/scripts/merge_tools/gitmerge_recursive_minimal.sh index 4c2aefb8ef..e7d916539a 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_minimal.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_minimal.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -# usage: ./gitmerge-recursive-minimal.sh +# usage: ./gitmerge_recursive_minimal.sh MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 diff --git a/src/scripts/merge_tools/gitmerge_recursive_myers.sh b/src/scripts/merge_tools/gitmerge_recursive_myers.sh index df12c4306c..f95f093ba7 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_myers.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_myers.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -# usage: ./gitmerge-recursive-myers.sh +# usage: ./gitmerge_recursive_myers.sh MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 diff --git a/src/scripts/merge_tools/gitmerge_recursive_patience.sh b/src/scripts/merge_tools/gitmerge_recursive_patience.sh index 6130ebbb4c..77e5a8e449 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_patience.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_patience.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -# usage: ./gitmerge-recursive-patience.sh +# usage: ./gitmerge_recursive_patience.sh MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 diff --git a/src/scripts/merge_tools/gitmerge_resolve.sh b/src/scripts/merge_tools/gitmerge_resolve.sh index 928a97960a..859faf70e2 100755 --- a/src/scripts/merge_tools/gitmerge_resolve.sh +++ b/src/scripts/merge_tools/gitmerge_resolve.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# usage: ./gitmerge-resolve.sh +# usage: ./gitmerge_resolve.sh MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)" clone_dir=$1 diff --git a/src/scripts/merge_tools/resolve-import-conflicts b/src/scripts/merge_tools/resolve-import-conflicts index 9778647846..a7f6e77de3 100755 --- a/src/scripts/merge_tools/resolve-import-conflicts +++ b/src/scripts/merge_tools/resolve-import-conflicts @@ -1,4 +1,5 @@ #!/bin/bash +# bash, not POSIX sh, because of "readarray". # This script edits files to remove conflict markers related to Java imports. # It works on all files given on the command line; diff --git a/src/scripts/merge_tools/resolve-import-conflicts-or-abort-merge b/src/scripts/merge_tools/resolve-import-conflicts-or-abort-merge new file mode 100755 index 0000000000..234d371d52 --- /dev/null +++ b/src/scripts/merge_tools/resolve-import-conflicts-or-abort-merge @@ -0,0 +1,18 @@ +#!/usr/bin/env sh + +# usage: ./resolve-import-conflicts-or-abort-merge +# Runs `resolve-import-conflicts`. +# If there are no remaining conflicts, exits with status 0. +# If some conflicts remain, ouputs "Conflict", aborts the merge, and exits with status 1. + + +"$MERGE_SCRIPTS_DIR"/resolve-import-conflicts + +# 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 +fi + +echo "Conflict" +git merge --abort +exit 1