Skip to contentSkip to conversation

git pull fails to exit with non-zero status after fatal error

DISCUSSION Larry Streepy 4 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

We have just upgraded to 1.5 (don't know if this is specific to 1.5, but just in case). When I perform a git-pull on a working repo that has a modified file, git pull refuses to do the pull, as shown below:

$ git pull
Updating b5d9263..506b347
tools/Pvt/Pvt.py: needs update
fatal: Entry 'tools/Pvt/Pvt.py' not uptodate. Cannot merge.
$ echo $?
0

Notice the exit status of 0. The driver scripts I use rely on a non-zero status to send me email when the git-pull fails, but this case eludes detection.

I'm assuming this is a bug, but if it's intended behavior I'd like to understand why it would use a 0 exit status after a issuing a fatal error.

Thanks,
Larry.

#1 lore raw

Hi,

Quoted 4 lines · Larry Streepy

We have just upgraded to 1.5 (don't know if this is specific to 1.5, but just in case). When I perform a git-pull on a working repo that has a modified file, git pull refuses to do the pull, as shown below:

Quoted 8 lines
$ git pull
Updating b5d9263..506b347
tools/Pvt/Pvt.py: needs update
fatal: Entry 'tools/Pvt/Pvt.py' not uptodate. Cannot merge.
$ echo $?
0

Notice the exit status of 0.

Does this fix it?

git-merge.sh +2 -1
index 498c938..6b23bf5 100755
@@ -295,8 +295,9 @@ f,*)
 	new_head=$(git-rev-parse --verify "$1^0") &&
 	git-read-tree -v -m -u --exclude-per-directory=.gitignore $head "$new_head" &&
 	finish "$new_head" "Fast forward"
+	ret=$?
 	dropsave
-	exit 0
+	exit $ret
 	;;
 ?,1,?*"$LF"?*,*)
 	# We are not doing octopus and not fast forward.  Need a
#2 lore raw

I'll give it a try and let you know.

Thanks for the quick feedback.

Larry.

Quoted 18 lines · Johannes Schindelin

Does this fix it?

git-merge.sh +2 -1
index 498c938..6b23bf5 100755
@@ -295,8 +295,9 @@ f,*)
 	new_head=$(git-rev-parse --verify "$1^0") &&
 	git-read-tree -v -m -u --exclude-per-directory=.gitignore $head "$new_head" &&
 	finish "$new_head" "Fast forward"
+	ret=$?
 	dropsave
-	exit 0
+	exit $ret
 	;;
 ?,1,?*"$LF"?*,*)
 	# We are not doing octopus and not fast forward.  Need a
#3 lore raw
In reply to Johannes Schindelin
Quoted 18 lines · Johannes Schindelin
Quoted 8 lines · Larry Streepy
$ git pull
Updating b5d9263..506b347
tools/Pvt/Pvt.py: needs update
fatal: Entry 'tools/Pvt/Pvt.py' not uptodate. Cannot merge.
$ echo $?
0

Notice the exit status of 0.

Does this fix it?

git-merge.sh +0 -0
index 498c938..6b23bf5 100755

git-merge.sh f,*) · line 303

Quoted 10 lines
git-merge.sh +2 -1
@@ -295,8 +295,9 @@ f,*)
 	new_head=$(git-rev-parse --verify "$1^0") &&
 	git-read-tree -v -m -u --exclude-per-directory=.gitignore $head "$new_head" &&
 	finish "$new_head" "Fast forward"
+	ret=$?
 	dropsave
-	exit 0
+	exit $ret
 	;;
 ?,1,?*"$LF"?*,*)
 	# We are not doing octopus and not fast forward.  Need a

The cation "dropsave" takes is to remove the files that are not needed after a successful merge, so I think it is better to fail if the && chain that ends with finish, like this.

git-merge.sh +1 -1
index 498c938..4afcd95 100755
@@ -294,7 +294,7 @@ f,*)
 	git-update-index --refresh 2>/dev/null
 	new_head=$(git-rev-parse --verify "$1^0") &&
 	git-read-tree -v -m -u --exclude-per-directory=.gitignore $head "$new_head" &&
-	finish "$new_head" "Fast forward"
+	finish "$new_head" "Fast forward" || exit
 	dropsave
 	exit 0
 	;;
#4 lore raw

Hi,

git-merge.sh f,*) · line 297

Quoted 2 lines · Junio C Hamano
git-merge.sh +1 -1
-	finish "$new_head" "Fast forward"
+	finish "$new_head" "Fast forward" || exit

Doesn't "exit" default to "exit 0"?

Ciao,
Dscho

#5 lore raw
Quoted 6 lines · Johannes Schindelin

git-merge.sh f,*) · line 297

Quoted 2 lines · Junio C Hamano
git-merge.sh +1 -1
-	finish "$new_head" "Fast forward"
+	finish "$new_head" "Fast forward" || exit

Doesn't "exit" default to "exit 0"?

No, it carries the exit status of the prior failed command if the prior command failed. ;-)

For what its worth, I learned that only while hacking on git-merge. I think it is highly non-obvious.

Signature · 1 line
Shawn.
#6 lore raw
Quoted 8 lines · Shawn O. Pearce
Quoted 6 lines · Johannes Schindelin

git-merge.sh f,*) · line 297

Quoted 2 lines · Junio C Hamano
git-merge.sh +1 -1
-	finish "$new_head" "Fast forward"
+	finish "$new_head" "Fast forward" || exit

Doesn't "exit" default to "exit 0"?

Quoted 5 lines

No, it carries the exit status of the prior failed command if the prior command failed. ;-)

For what its worth, I learned that only while hacking on git-merge. I think it is highly non-obvious.

Sorry to be a traditionalist. "sequence && of && commands || exit" is an established bourne shell idiom.

I do not mind if somebody proposed to change that to "... || exit $?" to unconfuse uninitiated, though.

#7 lore raw
In reply to Shawn O. Pearce

Hi,

Quoted 10 lines · Shawn O. Pearce
Quoted 6 lines · Johannes Schindelin

git-merge.sh f,*) · line 297

Quoted 2 lines · Junio C Hamano
git-merge.sh +1 -1
-	finish "$new_head" "Fast forward"
+	finish "$new_head" "Fast forward" || exit

Doesn't "exit" default to "exit 0"?

No, it carries the exit status of the prior failed command if the prior command failed. ;-)

You live and learn, live and learn...

Thanks,
Dscho