All of lore.kernel.org
 help / color / mirror / Atom feed
* What are cherry-pick's exit codes?
@ 2022-12-01  6:39 Sean Allred
  2022-12-01 12:19 ` Ævar Arnfjörð Bjarmason
  2022-12-01 14:43 ` Phillip Wood
  0 siblings, 2 replies; 5+ messages in thread
From: Sean Allred @ 2022-12-01  6:39 UTC (permalink / raw)
  To: git

Hi folks,

We're developing some internal tooling wrapping git-cherry-pick and need
to be able to distinguish its different error codes. Problem is: these
exit codes don't seem to be documented in git-cherry-pick.txt.

Looking at the source, I found myself down the rabbit-hole very quickly.
I'm not too familiar with the coding patterns quite yet -- but I'm
pretty sure I eventually found myself redirected to git-commit in one
case. At that point, I thought it better to ask here.

I'd like to document these exit codes in the manpage and I'm more than
happy to submit the patch, but I thought I'd confirm my understanding
first since it's based purely on reading the cherry-pick tests:

Exit code:

  - 0: success, sequencer complete -- no conflicts

  - 1: 'success', sequencer incomplete -- conflicts encountered

  - 127: fatal -- lots of reasons -- I'm guessing this is value for the
    'return -1' and 'return error(...)' statements speckled throughout
    the code, but it's been a long time since I cared about two's
    complement so I may be wrong here.

  - 128: fatal -- sequence is interrupted, possibly due to some other
    fatal error, e.g., 'commit doesn't exist' or 'mainline parent number
    doesn't exist'

  - 129: fatal -- there was nothing to cherry-pick at all (e.g. empty
    range)

I'm reasonably confident about 0/1 just anecdotally -- I'm less sure
about everything else.

Obviously the actual text put in the manpage should be friendlier and
possibly vaguer for clarity (paradoxical, perhaps, but it seems more
direct to say '0 for success, 1 for conflicts, and anything else is a
fatal error'), but I wanted to make sure that I have an actually-
accurate understanding rather than something only surface-level.

Two questions:

  1. Are the exit codes actually documented somewhere already that
     should simply be linked from git-cherry-pick.txt?

  2. If not, is the above listing the exit codes accurate and complete?

Thanks!

--
Sean Allred

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What are cherry-pick's exit codes?
  2022-12-01  6:39 What are cherry-pick's exit codes? Sean Allred
@ 2022-12-01 12:19 ` Ævar Arnfjörð Bjarmason
  2022-12-01 13:38   ` Sean Allred
  2022-12-01 14:43 ` Phillip Wood
  1 sibling, 1 reply; 5+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2022-12-01 12:19 UTC (permalink / raw)
  To: Sean Allred; +Cc: git


On Thu, Dec 01 2022, Sean Allred wrote:

> Hi folks,
>
> We're developing some internal tooling wrapping git-cherry-pick and need
> to be able to distinguish its different error codes. Problem is: these
> exit codes don't seem to be documented in git-cherry-pick.txt.
>
> Looking at the source, I found myself down the rabbit-hole very quickly.
> I'm not too familiar with the coding patterns quite yet -- but I'm
> pretty sure I eventually found myself redirected to git-commit in one
> case. At that point, I thought it better to ask here.

This is definitely worth doing, and there's a bit of a rabbit hole here,
so it'l also good you asked.

> I'd like to document these exit codes in the manpage and I'm more than
> happy to submit the patch, but I thought I'd confirm my understanding
> first since it's based purely on reading the cherry-pick tests:
>
> Exit code:
>
>   - 0: success, sequencer complete -- no conflicts
>
>   - 1: 'success', sequencer incomplete -- conflicts encountered

In general I think you'd do well to follow the template of what I did in
9144ba4cf52 (remote: add meaningful exit code on missing/existing,
2020-10-27).

In particular, I don't think we should exhaustively document exit codes
for a given command, as we really have a hard time controlling all the
possible values.

Rather, we should define specific non-zero values as having specific
meanings, as I did with "git remote" in that commit.

We'd also ideally leave "exit(1)" alone, and if we need to disambiguate
it start with "exit(2)", but maybe it's easy to make it unambiguous in
this case, or it's already unambiguous...


>   - 127: fatal -- lots of reasons -- I'm guessing this is value for the
>     'return -1' and 'return error(...)' statements speckled throughout
>     the code, but it's been a long time since I cared about two's
>     complement so I may be wrong here.

If it's "return -1" you generally end up with 255 in your shell,
although that's unportable both for the C language, and for POSIX.

See 19d75948ef7 (common-main.c: move non-trace2 exit() behavior out of
trace2.c, 2022-06-02) for some code dealing with that (where we fake up
the -1 to 255, for logging).

But from looking at cmd_cherry_pick() we catch any <0 return values and
die() on them, but maybe we exit() elsewhere? Do you have an example of
these.

>   - 128: fatal -- sequence is interrupted, possibly due to some other
>     fatal error, e.g., 'commit doesn't exist' or 'mainline parent number
>     doesn't exist'
>
>   - 129: fatal -- there was nothing to cherry-pick at all (e.g. empty
>     range)

I think as in 9144ba4cf52 (remote: add meaningful exit code on
missing/existing, 2020-10-27) it's good to just leave these
undocumented.

We typically return these when we invoke die() or usage_with_options()
(or similar).

So, if we are documenting them (which would be a good change, as an
aside) that probably belongs in gitcli(7), we could then reference that
from other man pages.

> I'm reasonably confident about 0/1 just anecdotally -- I'm less sure
> about everything else.
>
> Obviously the actual text put in the manpage should be friendlier and
> possibly vaguer for clarity (paradoxical, perhaps, but it seems more
> direct to say '0 for success, 1 for conflicts, and anything else is a
> fatal error'), but I wanted to make sure that I have an actually-
> accurate understanding rather than something only surface-level.
>
> Two questions:
>
>   1. Are the exit codes actually documented somewhere already that
>      should simply be linked from git-cherry-pick.txt?

No, just when we promise specific codes for specific
commands. E.g. git-remote, git-config etc. come to mind.

>   2. If not, is the above listing the exit codes accurate and complete?

I don't know, but skimming the code I don't see the "return 1", unless
by the above " - 1" you mean "minus one", i.e. 255.

I.e. cmd_cherry_pick() calls run_sequencer(), which on error seems to
return -1 for most things, which we then coerce to that die().

But I haven't looked in much detail, so...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What are cherry-pick's exit codes?
  2022-12-01 12:19 ` Ævar Arnfjörð Bjarmason
@ 2022-12-01 13:38   ` Sean Allred
  0 siblings, 0 replies; 5+ messages in thread
From: Sean Allred @ 2022-12-01 13:38 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason; +Cc: git


Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> In general I think you'd do well to follow the template of what I did in
> 9144ba4cf52 (remote: add meaningful exit code on missing/existing,
> 2020-10-27).
>
> In particular, I don't think we should exhaustively document exit codes
> for a given command, as we really have a hard time controlling all the
> possible values.
>
> Rather, we should define specific non-zero values as having specific
> meanings, as I did with "git remote" in that commit.

Definitely agree (this is roughly what I've had in my WIP patch), and
I'm glad to see precedent for an explicit 'exit status' section.

> We'd also ideally leave "exit(1)" alone, and if we need to disambiguate
> it start with "exit(2)", but maybe it's easy to make it unambiguous in
> this case, or it's already unambiguous...

I'm not 100% sure what you mean here, though. Do you mean that if
something returns an exit code of '1', we shouldn't touch it without
more specific review since it's more likely someone will be depending on
that value?

I think in my case, at least for what I see right now, the more urgent
need is getting exit codes documented -- but I can see where doing so
might create a situation where we can't improve the exit codes in the
future -- thus implying that the 'improving' and the 'documenting' may
need to be done in one go.

>>   - 127: fatal -- lots of reasons -- I'm guessing this is value for the
>>     'return -1' and 'return error(...)' statements speckled throughout
>>     the code, but it's been a long time since I cared about two's
>>     complement so I may be wrong here.
>
> If it's "return -1" you generally end up with 255 in your shell,
> although that's unportable both for the C language, and for POSIX.
>
> See 19d75948ef7 (common-main.c: move non-trace2 exit() behavior out of
> trace2.c, 2022-06-02) for some code dealing with that (where we fake up
> the -1 to 255, for logging).
>
> But from looking at cmd_cherry_pick() we catch any <0 return values and
> die() on them, but maybe we exit() elsewhere? Do you have an example of
> these.

No, I don't think so -- at least not by the point we hit
'run_git_command()'.

>>   - 128: fatal -- sequence is interrupted, possibly due to some other
>>     fatal error, e.g., 'commit doesn't exist' or 'mainline parent number
>>     doesn't exist'
>>
>>   - 129: fatal -- there was nothing to cherry-pick at all (e.g. empty
>>     range)
>
> I think as in 9144ba4cf52 (remote: add meaningful exit code on
> missing/existing, 2020-10-27) it's good to just leave these
> undocumented.
>
> We typically return these when we invoke die() or usage_with_options()
> (or similar).
>
> So, if we are documenting them (which would be a good change, as an
> aside) that probably belongs in gitcli(7), we could then reference that
> from other man pages.

Ah, gitcli(7) makes sense for these statuses. I'll see about submitting
a patch for review later tonight / this week; I'm cautiously optimistic
that it will be straightforward.

>>   2. If not, is the above listing the exit codes accurate and complete?
>
> I don't know, but skimming the code I don't see the "return 1", unless
> by the above " - 1" you mean "minus one", i.e. 255.

I do indeed mean 'negative one'.

> I.e. cmd_cherry_pick() calls run_sequencer(), which on error seems to
> return -1 for most things, which we then coerce to that die().
>
> But I haven't looked in much detail, so...

Seems like I (or someone) has some pretty 'fun' code tracing in my
future...

What's the next step here? Submit a patch with my best effort and suss
out the problems during review?

--
Sean Allred

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What are cherry-pick's exit codes?
  2022-12-01  6:39 What are cherry-pick's exit codes? Sean Allred
  2022-12-01 12:19 ` Ævar Arnfjörð Bjarmason
@ 2022-12-01 14:43 ` Phillip Wood
  2022-12-01 14:45   ` Sean Allred
  1 sibling, 1 reply; 5+ messages in thread
From: Phillip Wood @ 2022-12-01 14:43 UTC (permalink / raw)
  To: Sean Allred, git; +Cc: Ævar Arnfjörð Bjarmason

Hi Sean

On 01/12/2022 06:39, Sean Allred wrote:
> Hi folks,
> 
> We're developing some internal tooling wrapping git-cherry-pick and need
> to be able to distinguish its different error codes. Problem is: these
> exit codes don't seem to be documented in git-cherry-pick.txt.
> 
> Looking at the source, I found myself down the rabbit-hole very quickly.
> I'm not too familiar with the coding patterns quite yet -- but I'm
> pretty sure I eventually found myself redirected to git-commit in one
> case. At that point, I thought it better to ask here.
> 
> I'd like to document these exit codes in the manpage and I'm more than
> happy to submit the patch, but I thought I'd confirm my understanding
> first since it's based purely on reading the cherry-pick tests:
> 
> Exit code:
> 
>    - 0: success, sequencer complete -- no conflicts

I believe this is correct.

>    - 1: 'success', sequencer incomplete -- conflicts encountered

One can get exit code 1 without conflicts. One example is when it cannot 
cherry-pick a commit because it would overwrite an untracked file. 
Another example is when a picked commit would be empty because the 
changes are already in HEAD.

>    - 127: fatal -- lots of reasons -- I'm guessing this is value for the
>      'return -1' and 'return error(...)' statements speckled throughout
>      the code, but it's been a long time since I cared about two's
>      complement so I may be wrong here.
> 
>    - 128: fatal -- sequence is interrupted, possibly due to some other
>      fatal error, e.g., 'commit doesn't exist' or 'mainline parent number
>      doesn't exist'
> 
>    - 129: fatal -- there was nothing to cherry-pick at all (e.g. empty
>      range)

A high exit code from die() indicates something bad happened but I'm not 
sure one can rely on the exact value to tell you what happened.

Best Wishes

Phillip

> I'm reasonably confident about 0/1 just anecdotally -- I'm less sure
> about everything else.
> 
> Obviously the actual text put in the manpage should be friendlier and
> possibly vaguer for clarity (paradoxical, perhaps, but it seems more
> direct to say '0 for success, 1 for conflicts, and anything else is a
> fatal error'), but I wanted to make sure that I have an actually-
> accurate understanding rather than something only surface-level.
> 
> Two questions:
> 
>    1. Are the exit codes actually documented somewhere already that
>       should simply be linked from git-cherry-pick.txt?
> 
>    2. If not, is the above listing the exit codes accurate and complete?
> 
> Thanks!
> 
> --
> Sean Allred

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: What are cherry-pick's exit codes?
  2022-12-01 14:43 ` Phillip Wood
@ 2022-12-01 14:45   ` Sean Allred
  0 siblings, 0 replies; 5+ messages in thread
From: Sean Allred @ 2022-12-01 14:45 UTC (permalink / raw)
  To: phillip.wood; +Cc: git, Ævar Arnfjörð Bjarmason


Phillip Wood <phillip.wood123@gmail.com> writes:
> One can get exit code 1 without conflicts. One example is when it
> cannot cherry-pick a commit because it would overwrite an untracked
> file. Another example is when a picked commit would be empty because
> the changes are already in HEAD.

These are good cases to know/test, thank you!

--
Sean Allred

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-01 14:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01  6:39 What are cherry-pick's exit codes? Sean Allred
2022-12-01 12:19 ` Ævar Arnfjörð Bjarmason
2022-12-01 13:38   ` Sean Allred
2022-12-01 14:43 ` Phillip Wood
2022-12-01 14:45   ` Sean Allred

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.