git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* exit code from git reset
@ 2012-12-09 22:23 Martin von Zweigbergk
  2012-12-09 23:04 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Martin von Zweigbergk @ 2012-12-09 22:23 UTC (permalink / raw
  To: git

Hi,

"git reset" currently returns 0 (if successful) while "git reset
$pathspec" returns 0 iff the index matches HEAD after resetting (on
all paths, not just those matching $pathspec). The exit code doesn't
seem to be documented. Is there a reason they should behave
differently? If not, what would be the better behavior? I don't see
when the "git reset $pathspec" behavior" would be useful and it seems
safer for any existing scripts out there not to change the status code
for "git reset" (w/o paths). Scripts that run "git reset $pathspec"
probably already know to ignore (or use?) the exit code. Also, having
any non-zero exit code signal failure might actually be useful.

Changing "git reset $pathspec" to return 0 on success, regardless of
diff between HEAD and index, breaks 10 test cases (in
t2013-checkout-submodule.sh and t7102-reset.sh). These seem to do
"test_must_fail git reset $pathspec", but I have not been able to find
any motivation for expecting the failure.

It seems like this behavior has been there at least since the tests
were added in 359048d (Add tests for documented features of "git
reset"., 2007-09-11), just before reset became built-in.

Would a patch to change the exit code from "git reset $pathspec" be appreciated?

Martin

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

* Re: exit code from git reset
  2012-12-09 22:23 exit code from git reset Martin von Zweigbergk
@ 2012-12-09 23:04 ` Junio C Hamano
  2012-12-09 23:12   ` Martin von Zweigbergk
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2012-12-09 23:04 UTC (permalink / raw
  To: Martin von Zweigbergk; +Cc: git

Martin von Zweigbergk <martinvonz@gmail.com> writes:

> "git reset" currently returns 0 (if successful) while "git reset
> $pathspec" returns 0 iff the index matches HEAD after resetting (on
> all paths, not just those matching $pathspec).

So in short, you observed that either of them reports with its exit
code if the resulting index (not just any subpart, but always the
entire thing) matches the HEAD, e.g. "do we have change that will be
listed on 'will be committed' section in git status output?"

Sounds like one sane and consistent semantics to me.  I am not
saying that there cannot be other behaviours that are internally
consistent (e.g. the error code could have matched the number of
paths that are different between the index and the HED, or the error
code could have been zero for successful reset, non-zero for some
failure), but I am saying that the current behaviour gives _one_
sane and consistent meanings regardless of how you ran the command.

> The exit code doesn't seem to be documented.

Please make it so.

> Changing "git reset $pathspec" to return 0 on success, regardless of
> diff between HEAD and index, breaks 10 test cases (in
> t2013-checkout-submodule.sh and t7102-reset.sh). These seem to do
> "test_must_fail git reset $pathspec", but I have not been able to find
> any motivation for expecting the failure.

See above.

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

* Re: exit code from git reset
  2012-12-09 23:04 ` Junio C Hamano
@ 2012-12-09 23:12   ` Martin von Zweigbergk
  0 siblings, 0 replies; 3+ messages in thread
From: Martin von Zweigbergk @ 2012-12-09 23:12 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git

On Sun, Dec 9, 2012 at 3:04 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Martin von Zweigbergk <martinvonz@gmail.com> writes:
>
>> "git reset" currently returns 0 (if successful) while "git reset
>> $pathspec" returns 0 iff the index matches HEAD after resetting (on
>> all paths, not just those matching $pathspec).
>
> So in short, you observed that either of them reports with its exit
> code if the resulting index (not just any subpart, but always the
> entire thing) matches the HEAD, e.g. "do we have change that will be
> listed on 'will be committed' section in git status output?"
>
> Sounds like one sane and consistent semantics to me.

Heh, true, the behavior according to my description does make sense,
it's just that my description was wrong; sorry :-(.

What "git reset $pathspec" returns is not "whether HEAD differs from
index" (as I wrote), but "whether worktree differs from index". So
"git reset" and "git reset ." will return different exit codes if
there are changes in the worktree as compared to HEAD before the
invocation. I hope that's clearer.

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

end of thread, other threads:[~2012-12-09 23:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-09 22:23 exit code from git reset Martin von Zweigbergk
2012-12-09 23:04 ` Junio C Hamano
2012-12-09 23:12   ` Martin von Zweigbergk

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).