From 6313cb09a1de19d291469ad0904ed167c437f335 Mon Sep 17 00:00:00 2001 From: Benedikt schesch Date: Mon, 25 Sep 2023 18:04:26 -0700 Subject: [PATCH] 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