git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git-rev-parse incorrectly uses --default parameter when invalid revision is supplied

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
Jan 7, 2008, 23:38 UTC
Message-ID
<Pine.LNX.4.64.0801071653460.31161@torch.nrlssc.navy.mil>

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
Next: Junio C Hamano
Message 1 of 2 in “git-rev-parse incorrectly uses --default parameter when invalid revision is supplied”
  1. Brandon CaseyJan 7, 2008
  2. Junio C HamanoJan 8, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.