File tree 3 files changed +25
-3
lines changed
3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -337,10 +337,22 @@ def rev_parse(revision)
337
337
# For backwards compatibility with the old method name
338
338
alias :revparse :rev_parse
339
339
340
- def namerev ( string )
341
- command ( 'name-rev' , string ) . split [ 1 ]
340
+ # Find the first symbolic name for given commit_ish
341
+ #
342
+ # @param commit_ish [String] the commit_ish to find the symbolic name of
343
+ #
344
+ # @return [String, nil] the first symbolic name or nil if the commit_ish isn't found
345
+ #
346
+ # @raise [ArgumentError] if the commit_ish is a string starting with a hyphen
347
+ #
348
+ def name_rev ( commit_ish )
349
+ assert_args_are_not_options ( 'commit_ish' , commit_ish )
350
+
351
+ command ( 'name-rev' , commit_ish ) . split [ 1 ]
342
352
end
343
353
354
+ alias :namerev :name_rev
355
+
344
356
def object_type ( sha )
345
357
command ( 'cat-file' , '-t' , sha )
346
358
end
Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ def message
175
175
end
176
176
177
177
def name
178
- @base . lib . namerev ( sha )
178
+ @base . lib . name_rev ( sha )
179
179
end
180
180
181
181
def gtree
Original file line number Diff line number Diff line change @@ -198,6 +198,16 @@ def test_rev_parse_with_unknown_revision
198
198
end
199
199
end
200
200
201
+ def test_name_rev
202
+ assert_equal ( 'tags/v2.5~5' , @lib . name_rev ( '00ea60e' ) )
203
+ end
204
+
205
+ def test_name_rev_with_invalid_commit_ish
206
+ assert_raise ( ArgumentError ) do
207
+ @lib . name_rev ( '-1cc8667014381' )
208
+ end
209
+ end
210
+
201
211
def test_object_type
202
212
assert_equal ( 'commit' , @lib . object_type ( '1cc8667014381' ) ) # commit
203
213
assert_equal ( 'tree' , @lib . object_type ( '1cc8667014381^{tree}' ) ) #tree
You can’t perform that action at this time.
0 commit comments