git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git-rev-parse incorrectly uses --default parameter when invalid revision is supplied
@ 2008-01-07 23:38 Brandon Casey
  2008-01-08  0:21 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Brandon Casey @ 2008-01-07 23:38 UTC (permalink / raw)
  To: git


When rev-parse is called with an invalid revision parameter and
--default has been used to set a default revision, the output
will be based on the parameter to --default.

For example:

  This likely fails:
    $ git rev-parse --verify foobar
    fatal: Needed a single revision

  This likely succeeds but probably should fail:
    $ git rev-parse --verify --default refs/heads/master foobar
    b2e62a7dc6ba20a354d7590bf6a1d9264de7efe3


The documentation for rev-parse says:
   --default <arg>::
         If there is no parameter given by the user, use `<arg>`
         instead.


git-stash uses this command, so a typo could cause the wrong stash
to be applied.

   git stash apply stsh@{1}

If stash@{0} exists, it will be applied which is definitely not
what the user would want.

It is not straight forward to me how to modify builtin-rev-parse.c
to fix this.

-brandon

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

* Re: git-rev-parse incorrectly uses --default parameter when invalid revision is supplied
  2008-01-07 23:38 git-rev-parse incorrectly uses --default parameter when invalid revision is supplied Brandon Casey
@ 2008-01-08  0:21 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2008-01-08  0:21 UTC (permalink / raw)
  To: Brandon Casey; +Cc: git

Brandon Casey <casey@nrlssc.navy.mil> writes:

> When rev-parse is called with an invalid revision parameter and
> --default has been used to set a default revision, the output
> will be based on the parameter to --default.
>
> For example:
>
>  This likely fails:
>    $ git rev-parse --verify foobar
>    fatal: Needed a single revision
>
>  This likely succeeds but probably should fail:
>    $ git rev-parse --verify --default refs/heads/master foobar
>    b2e62a7dc6ba20a354d7590bf6a1d9264de7efe3
>
>
> The documentation for rev-parse says:
>   --default <arg>::
>         If there is no parameter given by the user, use `<arg>`
>         instead.
>
>
> git-stash uses this command, so a typo could cause the wrong stash
> to be applied.
>
>   git stash apply stsh@{1}
>
> If stash@{0} exists, it will be applied which is definitely not
> what the user would want.
>
> It is not straight forward to me how to modify builtin-rev-parse.c
> to fix this.

Two points.

 * The description for --default you quoted says "no parameter",
   but it should read "no non-flag rev parameter".

 * --verify needs to be whole lot more special cased in the
   codepath;

Currently, --verify just runs the command as if it was not
specified at all, but dies (1) as soon as it sees a second
non-flag rev arg (worse --- it dies *after* emitting it!), or
(2) at the end if it notices it did not emit any.  It does not
even barf if you say "git rev-parse --verify ^HEAD", which I
think is a misdesign.

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

end of thread, other threads:[~2008-01-08  0:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-07 23:38 git-rev-parse incorrectly uses --default parameter when invalid revision is supplied Brandon Casey
2008-01-08  0:21 ` Junio C Hamano

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 NNTP newsgroup(s).