9

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.

e40
  • 397
  • 1
  • 11
  • Is it a bash script or batch? – sashoalm Nov 02 '16 at 15:05
  • I don't know what OS you're on, but on linux with git >=2.0, I find that `cherry-pick` does indeed return a meaningful return code. I have mission-critical code that depends on this fact and it works flawlessly. – Mort Nov 02 '16 at 15:14
  • Using git 1.8. I guess I'll have to look into upgrading. Which exact git version are you using? – e40 Nov 02 '16 at 15:20
  • Frustrating part is I'm on CentOS 7.latest and I really don't want to upgrade git outside of the CentOS repos. – e40 Nov 02 '16 at 15:23

2 Answers2

4

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

$ ls /dev/null/foo
ls: /dev/null/foo: Not a directory
$ echo $?
1
djechlin
  • 59,258
  • 35
  • 162
  • 290
1

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

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • That's pretty horrible, especially if a series of cherry-picks are being done. However, if no other solution shows up, I guess this is it. – e40 Nov 02 '16 at 15:17
  • Well, you're using a commandline client to do automated things. Think about using libgit2 instead, I bet it has a better way to do what you want. You can use it from virtually any language. – rubenvb Nov 02 '16 at 15:35