{"thread":{"id":"11515","subject":"git-rev-parse incorrectly uses --default parameter when invalid revision is supplied","startedAt":"2008-01-07T23:38:42Z","lastAt":"2008-01-08T00:21:11Z","messageCount":2,"participants":["Brandon Casey","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"64687","messageId":"Pine.LNX.4.64.0801071653460.31161@torch.nrlssc.navy.mil","threadId":"11515","inReplyTo":null,"subject":"git-rev-parse incorrectly uses --default parameter when invalid revision is supplied","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-01-07T23:38:42Z","receivedAt":"2008-01-07T23:38:42Z","isPatch":false,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"\nWhen rev-parse is called with an invalid revision parameter and\n--default has been used to set a default revision, the output\nwill be based on the parameter to --default.\n\nFor example:\n\n  This likely fails:\n    $ git rev-parse --verify foobar\n    fatal: Needed a single revision\n\n  This likely succeeds but probably should fail:\n    $ git rev-parse --verify --default refs/heads/master foobar\n    b2e62a7dc6ba20a354d7590bf6a1d9264de7efe3\n\n\nThe documentation for rev-parse says:\n   --default <arg>::\n         If there is no parameter given by the user, use `<arg>`\n         instead.\n\n\ngit-stash uses this command, so a typo could cause the wrong stash\nto be applied.\n\n   git stash apply stsh@{1}\n\nIf stash@{0} exists, it will be applied which is definitely not\nwhat the user would want.\n\nIt is not straight forward to me how to modify builtin-rev-parse.c\nto fix this.\n\n-brandon\n"},{"id":"64689","messageId":"7vmyrhxj48.fsf@gitster.siamese.dyndns.org","threadId":"11515","inReplyTo":"Pine.LNX.4.64.0801071653460.31161@torch.nrlssc.navy.mil","subject":"Re: git-rev-parse incorrectly uses --default parameter when invalid revision is supplied","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-08T00:21:11Z","receivedAt":"2008-01-08T00:21:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brandon Casey <casey@nrlssc.navy.mil> writes:\n\n> When rev-parse is called with an invalid revision parameter and\n> --default has been used to set a default revision, the output\n> will be based on the parameter to --default.\n>\n> For example:\n>\n>  This likely fails:\n>    $ git rev-parse --verify foobar\n>    fatal: Needed a single revision\n>\n>  This likely succeeds but probably should fail:\n>    $ git rev-parse --verify --default refs/heads/master foobar\n>    b2e62a7dc6ba20a354d7590bf6a1d9264de7efe3\n>\n>\n> The documentation for rev-parse says:\n>   --default <arg>::\n>         If there is no parameter given by the user, use `<arg>`\n>         instead.\n>\n>\n> git-stash uses this command, so a typo could cause the wrong stash\n> to be applied.\n>\n>   git stash apply stsh@{1}\n>\n> If stash@{0} exists, it will be applied which is definitely not\n> what the user would want.\n>\n> It is not straight forward to me how to modify builtin-rev-parse.c\n> to fix this.\n\nTwo points.\n\n * The description for --default you quoted says \"no parameter\",\n   but it should read \"no non-flag rev parameter\".\n\n * --verify needs to be whole lot more special cased in the\n   codepath;\n\nCurrently, --verify just runs the command as if it was not\nspecified at all, but dies (1) as soon as it sees a second\nnon-flag rev arg (worse --- it dies *after* emitting it!), or\n(2) at the end if it notices it did not emit any.  It does not\neven barf if you say \"git rev-parse --verify ^HEAD\", which I\nthink is a misdesign.\n"}]}