Skip to content

Commit b47eedc

Browse files
mpapisjcouball
authored andcommitted
Improved error message of rev_parse
As described by git-rev-parse: Many Git porcelainish commands take mixture of flags (i.e. parameters that begin with a dash -) and parameters meant for the underlying git rev-list command they use internally and flags and parameters for the other commands they use downstream of git rev-list. This command is used to distinguish between them. Using the `--` to separate revisions from paths is at the core of git. I do not think this behavior will ever change. The message without the extra parameters: fatal: ambiguous argument 'v3': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' The message with new parameters: fatal: bad revision 'NOTFOUND' I think it's way more descriptive.
1 parent 9d44146 commit b47eedc

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/git/lib.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def full_log_commits(opts = {})
333333
def rev_parse(revision)
334334
assert_args_are_not_options('rev', revision)
335335

336-
command('rev-parse', revision)
336+
command('rev-parse', '--revs-only', '--end-of-options', revision, '--')
337337
end
338338

339339
# For backwards compatibility with the old method name

tests/units/test_lib.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def test_rev_parse_with_bad_revision
199199
end
200200

201201
def test_rev_parse_with_unknown_revision
202-
assert_raise(Git::FailedError) do
202+
assert_raise_with_message(Git::FailedError, /exit 128, stderr: "fatal: bad revision 'NOTFOUND'"/) do
203203
@lib.rev_parse('NOTFOUND')
204204
end
205205
end

0 commit comments

Comments
 (0)