Skip to content

Commit

Permalink
Improved handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mernst committed Sep 25, 2023
1 parent 32a4d41 commit f802736
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/git_hires_merge.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

# usage: ./git-hires-merge.sh <clone_dir> <branch-1> <branch-2>
# usage: ./git_hires_merge.sh <clone_dir> <branch-1> <branch-2>

clone_dir=$1
branch1=$2
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/merge_tools/gitmerge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_ort.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

# usage: ./gitmerge-ort.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_ort.sh <clone_dir> <branch-1> <branch-2>

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_ort_ignorespace.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

# usage: ./gitmerge-ort-ignorespace.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_ort_ignorespace.sh <clone_dir> <branch-1> <branch-2>

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
16 changes: 4 additions & 12 deletions src/scripts/merge_tools/gitmerge_ort_imports.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
#!/usr/bin/env sh

# usage: ./gitmerge-ort.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_ort_imports.sh <clone_dir> <branch-1> <branch-2>

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)
8 changes: 5 additions & 3 deletions src/scripts/merge_tools/gitmerge_ort_imports_ignorespace.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env sh

# usage: ./gitmerge-ort-ignorespace.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_ort_imports_ignorespace.sh <clone_dir> <branch-1> <branch-2>

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)
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_histogram.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

# usage: ./gitmerge-recursive-histogram.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_recursive_histogram.sh <clone_dir> <branch-1> <branch-2>

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_ignorespace.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

# usage: ./gitmerge-recursive-histogram.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_recursive_ignorespace.sh <clone_dir> <branch-1> <branch-2>

MERGE_DIR="$(dirname "$0")"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_minimal.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

# usage: ./gitmerge-recursive-minimal.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_recursive_minimal.sh <clone_dir> <branch-1> <branch-2>

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_myers.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

# usage: ./gitmerge-recursive-myers.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_recursive_myers.sh <clone_dir> <branch-1> <branch-2>

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_recursive_patience.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env sh

# usage: ./gitmerge-recursive-patience.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_recursive_patience.sh <clone_dir> <branch-1> <branch-2>

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/merge_tools/gitmerge_resolve.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# usage: ./gitmerge-resolve.sh <clone_dir> <branch-1> <branch-2>
# usage: ./gitmerge_resolve.sh <clone_dir> <branch-1> <branch-2>

MERGE_SCRIPTS_DIR="$(cd "$(dirname "$0")" && pwd -P)"
clone_dir=$1
Expand Down
1 change: 1 addition & 0 deletions src/scripts/merge_tools/resolve-import-conflicts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/scripts/merge_tools/resolve-import-conflicts-or-abort-merge
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f802736

Please sign in to comment.