diff --git a/merge-conflict b/merge-conflict index 2725e3521d243c5d754900106e5dff9b05586cc0..12853e314e9a4cc885c53329950974622bd7ab07 100755 --- a/merge-conflict +++ b/merge-conflict @@ -4,6 +4,10 @@ set -eu dest="${1:-master}" current="$(git symbolic-ref --short HEAD)" -[ "$current" != "$dest" ] || exit +[ "$current" != "$dest" ] || exit 0 -git format-patch "$(git merge-base HEAD "$dest")..$dest" --stdout | git apply --check - +patch="$(git format-patch "$(git merge-base HEAD "$dest")..$dest" --stdout)" + +[ "$patch" != "" ] || exit 0 + +echo "$patch" | git apply --check - diff --git a/tests/merge-conflict.bats b/tests/merge-conflict.bats index 9f5359b5b09b18a7a2f16b58272d3c93389bc077..cf2dd0b4f0aba0276b933732084e4f60c9a6c80e 100755 --- a/tests/merge-conflict.bats +++ b/tests/merge-conflict.bats @@ -9,16 +9,16 @@ export repo="$BATS_TMPDIR/testrepo" git init "$repo" cd "$repo" echo 1 > file - git -C "$repo" add "$repo/file" - git -C "$repo" commit -m "Initial commit." - git -C "$repo" checkout -b master2 - git -C "$repo" checkout -b no-conflict - git -C "$repo" checkout -b conflict - echo 2 > "$repo/file" - git -C "$repo" commit file -m "Conflict with master." - git -C "$repo" checkout master - echo 3 > "$repo/file" - git -C "$repo" commit file -m "Conflict with the conflict branch." + git add file + git commit -m "Initial commit." + git checkout -b master2 + git checkout -b no-conflict + git checkout -b conflict + echo 2 > file + git commit file -m "Conflict with master." + git checkout master + echo 3 > file + git commit file -m "Conflict with the conflict branch." fi }