[PATCH] mergetool-lib: refactor run_mergetool and check_unchanged

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This moves run_mergetool and check_unchanged into mergetool--lib.
git-mergetool no longer uses the global $status variable and instead
checks the return value of run_mergetool.

Signed-off-by: David Aguilar <davvid@xxxxxxxxx>
---
 git-mergetool--lib.sh |   21 +++++++++++++++++++--
 git-mergetool.sh      |   20 +-------------------
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index 91d5453..06d261a 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -22,9 +22,25 @@ get_merge_tool_path () {
 	echo "$path"
 }
 
-# Overridden in git-mergetool
 check_unchanged () {
-	true
+	if merge_mode; then
+		if test "$MERGED" -nt "$BACKUP"; then
+			status=0
+		else
+			while true; do
+				echo "$MERGED seems unchanged."
+				printf "Was the merge successful? [y/n] "
+				read answer < /dev/tty
+				case "$answer" in
+				y*|Y*) status=0; break ;;
+				n*|N*) status=1; break ;;
+				esac
+			done
+		fi
+	else
+		status=0
+	fi
+	return $status
 }
 
 valid_tool () {
@@ -213,4 +229,5 @@ run_mergetool () {
 		fi
 		;;
 	esac
+	return $status
 }
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 401c107..298b0a1 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -112,22 +112,6 @@ resolve_deleted_merge () {
 	done
 }
 
-check_unchanged () {
-    if test "$MERGED" -nt "$BACKUP" ; then
-	status=0;
-    else
-	while true; do
-	    echo "$MERGED seems unchanged."
-	    printf "Was the merge successful? [y/n] "
-	    read answer < /dev/tty
-	    case "$answer" in
-		y*|Y*) status=0; break ;;
-		n*|N*) status=1; break ;;
-	    esac
-	done
-    fi
-}
-
 checkout_staged_file () {
     tmpfile=$(expr "$(git checkout-index --temp --stage="$1" "$2")" : '\([^	]*\)	')
 
@@ -194,9 +178,7 @@ merge_file () {
     base_present &&
     present=true
 
-    run_mergetool "$merge_tool" "$present"
-
-    if test "$status" -ne 0; then
+    if ! run_mergetool "$merge_tool" "$present"; then
 	echo "merge of $MERGED failed" 1>&2
 	mv -- "$BACKUP" "$MERGED"
 
-- 
1.6.1.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux