Skip to content

Commit

Permalink
Modified merging scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-schesch committed Sep 26, 2023
1 parent 6c0cf83 commit 1ca6756
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 20 deletions.
21 changes: 7 additions & 14 deletions src/scripts/merge_tools/gitmerge.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
#!/usr/bin/env sh

# usage: ./gitmerge.sh <clone_dir> <branch-1> <branch-2> <strategy> [no-git-merge-abort]
# usage: ./gitmerge.sh <clone_dir> <branch-1> <branch-2> <strategy>
# <clone_dir> must contain a clone of a repository.
# <strategy> is arguments to `git merge`, including -s and possibly -X.
# Merges branch2 into branch1, in <clone_dir>, using merge strategy <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

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
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/scripts/merge_tools/gitmerge_ort.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/scripts/merge_tools/gitmerge_ort_ignorespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 9 additions & 3 deletions src/scripts/merge_tools/gitmerge_ort_imports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 8 additions & 3 deletions src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/scripts/merge_tools/gitmerge_recursive_histogram.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/scripts/merge_tools/gitmerge_recursive_minimal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/scripts/merge_tools/gitmerge_recursive_myers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/scripts/merge_tools/gitmerge_recursive_patience.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1ca6756

Please sign in to comment.