Skip to content
  • Jeff King's avatar
    rev-parse: correctly diagnose revision errors before "--" · 14185673
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    Rev-parse understands that a "--" may separate revisions and
    filenames, and that anything after the "--" is taken as-is.
    However, it does not understand that anything before the
    token must be a revision (which is the usual rule
    implemented by the setup_revisions parser).
    
    Since rev-parse prefers revisions to files when parsing
    before the "--", we end up with the correct result (if such
    an argument is a revision, we parse it as one, and if it is
    not, it is an error either way).  However, we misdiagnose
    the errors:
    
      $ git rev-parse foobar -- >/dev/null
      fatal: ambiguous argument 'foobar': unknown revision or path not in the working tree.
      Use '--' to separate paths from revisions, like this:
      'git <command> [<revision>...] -- [<file>...]'
    
      $ >foobar
      $ git rev-parse foobar -- >/dev/null
      fatal: bad flag '--' used after filename
    
    In both cases, we should know that the real error is that
    "foobar" is meant to be a revision, but could not be
    resolved.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Reviewed-by: default avatarJonathan Nieder <jrnieder@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    14185673