From 511ff06e71bc820c8dce3c60edc1fb4ca63114d0 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Tue, 13 Jun 2017 16:22:33 +0300
Subject: [PATCH] - Fix tests. - Fix issue when diff is empty. - Forgot
 --stdout in patch generation. - Fix issue when it's the same branch.

---
 merge-conflict            |  8 ++++++--
 tests/merge-conflict.bats | 20 ++++++++++----------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/merge-conflict b/merge-conflict
index 2725e35..12853e3 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 9f5359b..cf2dd0b 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
 }
 
-- 
GitLab