git: different possible output of cherry-pick

601 views Asked by At

I am trying write a script that automate git cherry-pick. I need to be able to handle all possible failure of git cherry-pick. So far, I've counted 3 kind of outputs:

+Cherry-pick success, no merge conflict. Exit code is 0. The output look like this:

git cp ed54dfc
[dev/nango/cp3_nocconflict 97f2dce] test cp1
1 file changed, 1 insertion(+)
create mode 100644 foo.txt

+Cherry-pick commit that already in the branch, or no code is committed. Exit code 1. The output look like this:

You are currently cherry-picking commit 61ff477.


It took 3.90 seconds to enumerate untracked files. 'status -uno'
may speed it up, but you have to be careful not to forget to add
new files yourself (see 'git help status').
nothing to commit, working directory clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

git commit --allow-empty

Otherwise, please use 'git reset'

+Cherry-pick throws a merge conflict. Exit code 1:

error: could not apply ed54dfc... test cp1
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

Is there any other possibility of cherry-pick? I take a look at the doc and there is not much mention about possible outcome of cherry-pick.

Thanks.

1

There are 1 answers

0
VonC On BEST ANSWER

If you want to acount for all possible scenario, you can base your tests on the ones for git cherry-pick present in the git repo, namely:

You might not discover any more output message, but at least you will test those against all known test cases for that command.