git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Return non-zero status from pull if merge fails.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Nov 7, 2006, 18:10 UTC
Message-ID
<20061107181053.GA26856@spearce.org>

If the merge operation fails during git-pull it usually exits with a non-zero exit status to let the caller know it failed. But git-pull tossed that status away and always returned 0 (success), leading to confusing output in any higher level interface which supplied both the console output (showing the merge failure) and the exit status (showing success).

So now git-pull just exec's git-merge, allowing its exit status to be reported directly to the caller.

There were also a number of cases within git-merge which terminated with a success (0) exit status despite having been caused by failure to merge. This is equally misleading and should return 1 instead.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 git-merge.sh |   10 +++++-----
 git-pull.sh  |    2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/git-merge.sh b/git-merge.sh
index cb09438..7725908 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -203,7 +203,7 @@ f,*)
 	git-update-index --refresh 2>/dev/null
 	new_head=$(git-rev-parse --verify "$1^0") &&
 	git-read-tree -u -v -m $head "$new_head" &&
-	finish "$new_head" "Fast forward"
+	finish "$new_head" "Fast forward" || exit 1
 	dropsave
 	exit 0
 	;;
@@ -214,7 +214,7 @@ f,*)
 ?,1,*,)
 	# We are not doing octopus, not fast forward, and have only
 	# one common.  See if it is really trivial.
-	git var GIT_COMMITTER_IDENT >/dev/null || exit
+	git var GIT_COMMITTER_IDENT >/dev/null || exit 1
 
 	echo "Trying really trivial in-index merge..."
 	git-update-index --refresh 2>/dev/null
@@ -225,7 +225,7 @@ f,*)
 	    result_commit=$(
 	        echo "$merge_msg" |
 	        git-commit-tree $result_tree -p HEAD -p "$1"
-	    ) || exit
+	    ) || exit 1
 	    finish "$result_commit" "In-index merge"
 	    dropsave
 	    exit 0
@@ -253,7 +253,7 @@ f,*)
 esac
 
 # We are going to make a new commit.
-git var GIT_COMMITTER_IDENT >/dev/null || exit
+git var GIT_COMMITTER_IDENT >/dev/null || exit 1
 
 # At this point, we need a real merge.  No matter what strategy
 # we use, it would operate on the index, possibly affecting the
@@ -327,7 +327,7 @@ done
 if test '' != "$result_tree"
 then
     parents=$(git-show-branch --independent "$head" "$@" | sed -e 's/^/-p /')
-    result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree $parents) || exit
+    result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree $parents) || exit 1
     finish "$result_commit" "Merge made by $wt_strategy."
     dropsave
     exit 0
diff --git a/git-pull.sh b/git-pull.sh
index ed04e7d..d10fcdd 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -102,6 +102,6 @@ case "$strategy_args" in
 esac
 
 merge_name=$(git-fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
-git-merge "--reflog-action=pull $*" \
+exec git-merge "--reflog-action=pull $*" \
 	$no_summary $no_commit $squash $strategy_args \
 	"$merge_name" HEAD $merge_head
Next: Junio C Hamano
Message 1 of 5 in “Return non-zero status from pull if merge fails.”
  1. Return non-zero status from pull if merge fails.Shawn O. Pearce, Nov 7, 2006
  2. Junio C HamanoNov 8, 2006
  3. Shawn PearceNov 8, 2006
  4. Junio C HamanoNov 8, 2006
  5. Shawn PearceNov 8, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.