Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exit code when calling resolve-import-conflicts #217

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/scripts/merge_tools/gitmerge_ort.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benedikt-schesch Why is this necessary? The script should exit with the same status as the last command in it, so this if construct seems unnecessary (throughout).

exit 1
fi
4 changes: 3 additions & 1 deletion src/scripts/merge_tools/gitmerge_ort_ignorespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions src/scripts/merge_tools/gitmerge_ort_imports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/scripts/merge_tools/gitmerge_recursive_histogram.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/scripts/merge_tools/gitmerge_recursive_minimal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/scripts/merge_tools/gitmerge_recursive_myers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/scripts/merge_tools/gitmerge_recursive_patience.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 16 additions & 4 deletions src/scripts/merge_tools/resolve-import-conflicts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

6 changes: 5 additions & 1 deletion src/scripts/merge_tools/resolve-import-conflicts-in-file.py
Original file line number Diff line number Diff line change
@@ -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.
"""


Expand Down