threads / discuss / 44414

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

Subject: How can I tell, from a script, if “git cherry-pick” fails?

## tl;dr

3 messages between Nov 2, 2016 and Nov 2, 2016.

replies: 2people: 2as markdown or json

Kevin Layer· Nov 2, 2016, 15:14 UTC · lore

If the cherry-pick fails due to a merge conflict, it just returns an exit status of 0. I have a script that does a series of cherry-picks and I need to know if they succeed.

I'm sure this has been covered before.
Using git version 1.8.3.1.
Thank you.
Kevin
Kevin Layer· Nov 2, 2016, 15:32 UTC · re: Kevin Layer · lore

Re: How can I tell, from a script, if “git cherry-pick” fails?

Nevermind. It's working as it should. The script that was doing the cherry-pick was doing it in an if and I neglected to exit with a non-zero status. Sorry for the noise.

On Wed, Nov 2, 2016 at 8:14 AM, Kevin Layer <layer@known.net> wrote:
Show 11 quoted lines
> If the cherry-pick fails due to a merge conflict, it just returns an
> exit status of 0.  I have a script that does a series of cherry-picks
> and I need to know if they succeed.
>
> I'm sure this has been covered before.
>
> Using git version 1.8.3.1.
>
> Thank you.
>
> Kevin
Pranit Bauva· Nov 2, 2016, 15:36 UTC · re: Kevin Layer · lore

Re: How can I tell, from a script, if “git cherry-pick” fails?

Hey Kevin,
On Wed, Nov 2, 2016 at 8:44 PM, Kevin Layer <layer@known.net> wrote:
> If the cherry-pick fails due to a merge conflict, it just returns an
> exit status of 0.  I have a script that does a series of cherry-picks
> and I need to know if they succeed.

Well, I haven't checked what it returns in git 2.10, but you can always redirect the stdout and stderr to the output and grep for the text which it shows in the actual output. Here[1] is an example of how to do it.

[1]: https://github.com/git/git/blob/master/t/t3507-cherry-pick-conflict.sh#L42-L55

Regards, Pranit Bauva

← back to recent threads