From 32a4d4121939761ad79e83ff644102b9ea34d350 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 25 Sep 2023 16:26:18 -0700 Subject: [PATCH 1/8] Handle exit code in resolve-import-conflicts --- src/scripts/merge_tools/gitmerge.sh | 19 +++++++++++++------ .../merge_tools/gitmerge_ort_imports.sh | 14 ++++++++++++-- .../merge_tools/resolve-import-conflicts | 3 +++ .../resolve-import-conflicts-in-file.py | 6 +++++- 4 files changed, 33 insertions(+), 9 deletions(-) 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. """ From f8027367d4f378e88f7c755b05d6e52b56ea0b03 Mon Sep 17 00:00:00 2001 From: Michael Ernst Date: Mon, 25 Sep 2023 16:45:12 -0700 Subject: [PATCH 2/8] Improved handling --- src/scripts/merge_tools/git_hires_merge.sh | 2 +- src/scripts/merge_tools/gitmerge.sh | 8 ++++---- src/scripts/merge_tools/gitmerge_ort.sh | 2 +- .../merge_tools/gitmerge_ort_ignorespace.sh | 2 +- .../merge_tools/gitmerge_ort_imports.sh | 16 ++++------------ .../gitmerge_ort_imports_ignorespace.sh | 8 +++++--- .../gitmerge_recursive_histogram.sh | 2 +- .../gitmerge_recursive_ignorespace.sh | 2 +- .../merge_tools/gitmerge_recursive_minimal.sh | 2 +- .../merge_tools/gitmerge_recursive_myers.sh | 2 +- .../merge_tools/gitmerge_recursive_patience.sh | 2 +- src/scripts/merge_tools/gitmerge_resolve.sh | 2 +- .../merge_tools/resolve-import-conflicts | 1 + .../resolve-import-conflicts-or-abort-merge | 18 ++++++++++++++++++ 14 files changed, 41 insertions(+), 28 deletions(-) create mode 100755 src/scripts/merge_tools/resolve-import-conflicts-or-abort-merge 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 From 6313cb09a1de19d291469ad0904ed167c437f335 Mon Sep 17 00:00:00 2001 From: Benedikt schesch Date: Mon, 25 Sep 2023 18:04:26 -0700 Subject: [PATCH 3/8] Resolve import conflicts in one script --- .../merge_tools/gitmerge_ort_imports.sh | 2 +- .../gitmerge_ort_imports_ignorespace.sh | 2 +- .../merge_tools/resolve-import-conflicts | 19 +++++++++++++++---- .../resolve-import-conflicts-or-abort-merge | 18 ------------------ 4 files changed, 17 insertions(+), 24 deletions(-) delete mode 100755 src/scripts/merge_tools/resolve-import-conflicts-or-abort-merge diff --git a/src/scripts/merge_tools/gitmerge_ort_imports.sh b/src/scripts/merge_tools/gitmerge_ort_imports.sh index 91d199fd90..87bfb15c05 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports.sh @@ -11,4 +11,4 @@ if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strateg exit fi -(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts-or-abort-merge) +(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts) diff --git a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh index bfd82af44b..5151e81037 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh @@ -11,4 +11,4 @@ if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strateg exit fi -(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts-or-abort-merge) +(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts) diff --git a/src/scripts/merge_tools/resolve-import-conflicts b/src/scripts/merge_tools/resolve-import-conflicts index a7f6e77de3..fa6c1d4726 100755 --- a/src/scripts/merge_tools/resolve-import-conflicts +++ b/src/scripts/merge_tools/resolve-import-conflicts @@ -9,8 +9,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. +# 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' .) @@ -24,8 +25,18 @@ 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-or-abort-merge b/src/scripts/merge_tools/resolve-import-conflicts-or-abort-merge deleted file mode 100755 index 234d371d52..0000000000 --- a/src/scripts/merge_tools/resolve-import-conflicts-or-abort-merge +++ /dev/null @@ -1,18 +0,0 @@ -#!/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 From 6c0cf836103f6f60b8979bda7b3513b926778513 Mon Sep 17 00:00:00 2001 From: Benedikt schesch Date: Mon, 25 Sep 2023 21:38:54 -0700 Subject: [PATCH 4/8] Style Fix --- src/scripts/merge_tools/resolve-import-conflicts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/scripts/merge_tools/resolve-import-conflicts b/src/scripts/merge_tools/resolve-import-conflicts index fa6c1d4726..fc4605f54a 100755 --- a/src/scripts/merge_tools/resolve-import-conflicts +++ b/src/scripts/merge_tools/resolve-import-conflicts @@ -21,8 +21,6 @@ fi SCRIPTDIR="$(cd "$(dirname "$0")" && pwd -P)" -status=0 - for file in "${files[@]}" ; do if ! "${SCRIPTDIR}"/resolve-import-conflicts-in-file.py "$file" ; then echo "Error in $file" From 1ca67562fae8eb11790e653459c470de60b8bf9c Mon Sep 17 00:00:00 2001 From: Benedikt schesch Date: Mon, 25 Sep 2023 22:51:09 -0700 Subject: [PATCH 5/8] Modified merging scripts --- src/scripts/merge_tools/gitmerge.sh | 21 +++++++------------ src/scripts/merge_tools/gitmerge_ort.sh | 3 +++ .../merge_tools/gitmerge_ort_ignorespace.sh | 3 +++ .../merge_tools/gitmerge_ort_imports.sh | 12 ++++++++--- .../gitmerge_ort_imports_ignorespace.sh | 11 +++++++--- .../gitmerge_recursive_histogram.sh | 3 +++ .../gitmerge_recursive_ignorespace.sh | 3 +++ .../merge_tools/gitmerge_recursive_minimal.sh | 3 +++ .../merge_tools/gitmerge_recursive_myers.sh | 3 +++ .../gitmerge_recursive_patience.sh | 3 +++ 10 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/scripts/merge_tools/gitmerge.sh b/src/scripts/merge_tools/gitmerge.sh index bbf3e293f2..1c2032d58a 100755 --- a/src/scripts/merge_tools/gitmerge.sh +++ b/src/scripts/merge_tools/gitmerge.sh @@ -1,19 +1,16 @@ #!/usr/bin/env sh -# usage: ./gitmerge.sh [no-git-merge-abort] +# usage: ./gitmerge.sh # 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 . -# For merge success, return code is 0. -# For merge failure: -# * return code is 1. -# * outputs "Conflict" and aborts the merge, -# unless a non-empty 5th command-line argument is provided. +# Return code is 0 for merge success, 1 for merge failure. +# For merge failure, also outputs "Conflict" and aborts the merge. set -o nounset -if [ "$#" -ne 4 ] && [ "$#" -ne 5 ]; then - echo "Usage: $0 CLONE_DIR BRANCH1 BRANCH2 STRATEGY [no-git-merge-abort]" >&2 +if [ "$#" -ne 4 ]; then + echo "Usage: $0 CLONE_DIR BRANCH1 BRANCH2 STRATEGY" >&2 exit 1 fi @@ -21,8 +18,6 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy=$4 -# If this variable is non-empty, don't output "Conflict" or run `git merge --abort`. -no_git_merge_abort=$5 # perform merge cd "$clone_dir" || exit 1 @@ -34,10 +29,8 @@ retVal=$? # report conflicts if [ $retVal -ne 0 ]; then - if [ -z "$no_git_merge_abort" ] ; then - echo "Conflict" - git merge --abort - fi + echo "Conflict" + git merge --abort fi exit $retVal diff --git a/src/scripts/merge_tools/gitmerge_ort.sh b/src/scripts/merge_tools/gitmerge_ort.sh index d8a695734b..5870c56a91 100755 --- a/src/scripts/merge_tools/gitmerge_ort.sh +++ b/src/scripts/merge_tools/gitmerge_ort.sh @@ -8,3 +8,6 @@ branch1=$2 branch2=$3 strategy="-s ort" "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if [ $? -ne 0 ] ; 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..53805e7418 100755 --- a/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh @@ -8,3 +8,6 @@ branch1=$2 branch2=$3 strategy="-s ort -Xignore-space-change" "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if [ $? -ne 0 ] ; 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 87bfb15c05..b9ba8315f2 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports.sh @@ -7,8 +7,14 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s ort" -if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" "no-git-merge-abort" ; then - exit +"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if [ $? -e 0 ] ; then + exit 0 +fi + +cd "$clone_dir" +"$MERGE_SCRIPTS_DIR"/resolve-import-conflicts +if [ $? -ne 0 ] ; then + exit 1 fi -(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts) diff --git a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh index 5151e81037..d8118fa3e3 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh @@ -7,8 +7,13 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s ort -Xignore-space-change" -if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" "no-git-merge-abort" ; then - exit +"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if [ $? -e 0 ] ; then + exit 0 fi -(cd "$clone_dir" && "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts) +cd "$clone_dir" +"$MERGE_SCRIPTS_DIR"/resolve-import-conflicts +if [ $? -ne 0 ] ; 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..afddba1160 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_histogram.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_histogram.sh @@ -8,3 +8,6 @@ branch1=$2 branch2=$3 strategy="-s recursive -Xdiff-algorithm=histogram" "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if [ $? -ne 0 ] ; 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..44de249969 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh @@ -8,3 +8,6 @@ branch1=$2 branch2=$3 strategy="-s recursive -Xignore-space-change" "$MERGE_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if [ $? -ne 0 ] ; 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..7cf08a7dc3 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_minimal.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_minimal.sh @@ -8,3 +8,6 @@ branch1=$2 branch2=$3 strategy="-s recursive -Xdiff-algorithm=minimal" "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if [ $? -ne 0 ] ; 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..035864ba4c 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_myers.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_myers.sh @@ -8,3 +8,6 @@ branch1=$2 branch2=$3 strategy="-s recursive -Xdiff-algorithm=myers" "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if [ $? -ne 0 ] ; 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..619c0830a9 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_patience.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_patience.sh @@ -8,3 +8,6 @@ branch1=$2 branch2=$3 strategy="-s recursive -Xdiff-algorithm=patience" "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" +if [ $? -ne 0 ] ; then + exit 1 +fi From 3df8d8a9641091f10c2cd19fcd3982fe54452d49 Mon Sep 17 00:00:00 2001 From: Benedikt schesch Date: Mon, 25 Sep 2023 22:59:48 -0700 Subject: [PATCH 6/8] Fix Style --- src/scripts/merge_tools/gitmerge_ort.sh | 3 +-- src/scripts/merge_tools/gitmerge_ort_ignorespace.sh | 3 +-- src/scripts/merge_tools/gitmerge_ort_imports.sh | 7 ++----- .../merge_tools/gitmerge_ort_imports_ignorespace.sh | 6 ++---- src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh | 5 ++--- src/scripts/merge_tools/gitmerge_recursive_minimal.sh | 5 ++--- src/scripts/merge_tools/gitmerge_recursive_myers.sh | 3 +-- src/scripts/merge_tools/gitmerge_recursive_patience.sh | 3 +-- 8 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/scripts/merge_tools/gitmerge_ort.sh b/src/scripts/merge_tools/gitmerge_ort.sh index 5870c56a91..a72d9ee50c 100755 --- a/src/scripts/merge_tools/gitmerge_ort.sh +++ b/src/scripts/merge_tools/gitmerge_ort.sh @@ -7,7 +7,6 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s ort" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" -if [ $? -ne 0 ] ; then +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 53805e7418..a085edcaa6 100755 --- a/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_ignorespace.sh @@ -7,7 +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 [ $? -ne 0 ] ; then +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 b9ba8315f2..56c6275ff8 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports.sh @@ -7,14 +7,11 @@ clone_dir=$1 branch1=$2 branch2=$3 strategy="-s ort" -"$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy" -if [ $? -e 0 ] ; then +if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then exit 0 fi cd "$clone_dir" -"$MERGE_SCRIPTS_DIR"/resolve-import-conflicts -if [ $? -ne 0 ] ; then +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 d8118fa3e3..a4291bb18a 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh @@ -7,13 +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 [ $? -e 0 ] ; then +if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then exit 0 fi cd "$clone_dir" -"$MERGE_SCRIPTS_DIR"/resolve-import-conflicts -if [ $? -ne 0 ] ; then +if ! "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts; 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 44de249969..519db73d40 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh @@ -7,7 +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 [ $? -ne 0 ] ; then - exit 1 +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 7cf08a7dc3..e5a6edff9f 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_minimal.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_minimal.sh @@ -7,7 +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 [ $? -ne 0 ] ; then - exit 1 +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 035864ba4c..3fafe5e977 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_myers.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_myers.sh @@ -7,7 +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 [ $? -ne 0 ] ; then +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 619c0830a9..ef47dc2cab 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_patience.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_patience.sh @@ -7,7 +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 [ $? -ne 0 ] ; then +if ! "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then exit 1 fi From d84877a9f4710a629d9ecb62af8d6e8b9b90ad5b Mon Sep 17 00:00:00 2001 From: Benedikt schesch Date: Mon, 25 Sep 2023 23:00:04 -0700 Subject: [PATCH 7/8] Further fix style --- src/scripts/merge_tools/gitmerge_recursive_histogram.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/scripts/merge_tools/gitmerge_recursive_histogram.sh b/src/scripts/merge_tools/gitmerge_recursive_histogram.sh index afddba1160..3d8238775a 100755 --- a/src/scripts/merge_tools/gitmerge_recursive_histogram.sh +++ b/src/scripts/merge_tools/gitmerge_recursive_histogram.sh @@ -7,7 +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 [ $? -ne 0 ] ; then +if ! "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strategy"; then exit 1 fi From 9ebc8ca1c72166ac61d9d1774cf780b9e2441065 Mon Sep 17 00:00:00 2001 From: Benedikt schesch Date: Mon, 25 Sep 2023 23:01:48 -0700 Subject: [PATCH 8/8] Further fix style --- src/scripts/merge_tools/gitmerge_ort_imports.sh | 2 +- src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scripts/merge_tools/gitmerge_ort_imports.sh b/src/scripts/merge_tools/gitmerge_ort_imports.sh index 56c6275ff8..cf0309d91f 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports.sh @@ -11,7 +11,7 @@ if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strateg exit 0 fi -cd "$clone_dir" +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 a4291bb18a..b6ae36b948 100755 --- a/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh +++ b/src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh @@ -11,7 +11,7 @@ if "$MERGE_SCRIPTS_DIR"/gitmerge.sh "$clone_dir" "$branch1" "$branch2" "$strateg exit 0 fi -cd "$clone_dir" +cd "$clone_dir" || exit 1 if ! "$MERGE_SCRIPTS_DIR"/resolve-import-conflicts; then exit 1 fi