Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell, from a script, if "git cherry-pick" fails?

If the cherry-pick fails due to a merge conflict, it just returns an exit status of 0.

Please don't tell me about --abort. I need to detect, in a script, if the original cherry-pick command fails.

Using git version 1.8.3.1 on CentOS 7.2.

EDIT: my script was doing the cherry-pick in an if ! and I didn't exit properly in the then clause with a non-zero exit. Sorry for the noise.

like image 452
e40 Avatar asked Nov 02 '16 15:11

e40


2 Answers

$? holds the return code of the last process run in bash.

$ ls /dev/null/foo
ls: /dev/null/foo: Not a directory
$ echo $?
1
like image 114
djechlin Avatar answered Oct 17 '22 17:10

djechlin


You can call git status or equivalent and inspect its output for a normal "1 ahead of tracking" status or a "merge" status.

like image 44
rubenvb Avatar answered Oct 17 '22 18:10

rubenvb