@@ -169,27 +169,33 @@ def repository_default_branch(repository)
169
169
170
170
## READ COMMANDS ##
171
171
172
+ # Finds most recent tag that is reachable from a commit
172
173
#
173
- # Returns most recent tag that is reachable from a commit
174
+ # @see https://git-scm.com/docs/git-describe git-describe
174
175
#
175
- # accepts options:
176
- # :all
177
- # :tags
178
- # :contains
179
- # :debug
180
- # :exact_match
181
- # :dirty
182
- # :abbrev
183
- # :candidates
184
- # :long
185
- # :always
186
- # :math
187
- #
188
- # @param [String|NilClass] committish target commit sha or object name
189
- # @param [{Symbol=>Object}] opts the given options
190
- # @return [String] the tag name
191
- #
192
- def describe ( committish = nil , opts = { } )
176
+ # @param commit_ish [String, nil] target commit sha or object name
177
+ #
178
+ # @param opts [Hash] the given options
179
+ #
180
+ # @option opts :all [Boolean]
181
+ # @option opts :tags [Boolean]
182
+ # @option opts :contains [Boolean]
183
+ # @option opts :debug [Boolean]
184
+ # @option opts :long [Boolean]
185
+ # @option opts :always [Boolean]
186
+ # @option opts :exact_match [Boolean]
187
+ # @option opts :dirty [true, String]
188
+ # @option opts :abbrev [String]
189
+ # @option opts :candidates [String]
190
+ # @option opts :match [String]
191
+ #
192
+ # @return [String] the tag name
193
+ #
194
+ # @raise [ArgumentError] if the commit_ish is a string starting with a hyphen
195
+ #
196
+ def describe ( commit_ish = nil , opts = { } )
197
+ assert_args_are_not_options ( 'commit-ish object' , commit_ish )
198
+
193
199
arr_opts = [ ]
194
200
195
201
arr_opts << '--all' if opts [ :all ]
@@ -207,7 +213,7 @@ def describe(committish=nil, opts={})
207
213
arr_opts << "--candidates=#{ opts [ :candidates ] } " if opts [ :candidates ]
208
214
arr_opts << "--match=#{ opts [ :match ] } " if opts [ :match ]
209
215
210
- arr_opts << committish if committish
216
+ arr_opts << commit_ish if commit_ish
211
217
212
218
return command ( 'describe' , *arr_opts )
213
219
end
@@ -534,15 +540,15 @@ def grep(string, opts = {})
534
540
# @raise [ArgumentError] if any of the parameters are a string starting with a hyphen
535
541
# @return [void]
536
542
#
537
- def validate_no_options ( arg_name , *args )
543
+ def assert_args_are_not_options ( arg_name , *args )
538
544
invalid_args = args . select { |arg | arg &.start_with? ( '-' ) }
539
545
if invalid_args . any?
540
546
raise ArgumentError , "Invalid #{ arg_name } : '#{ invalid_args . join ( "', '" ) } '"
541
547
end
542
548
end
543
549
544
550
def diff_full ( obj1 = 'HEAD' , obj2 = nil , opts = { } )
545
- validate_no_options ( 'commit or commit range' , obj1 , obj2 )
551
+ assert_args_are_not_options ( 'commit or commit range' , obj1 , obj2 )
546
552
547
553
diff_opts = [ '-p' ]
548
554
diff_opts << obj1
@@ -553,7 +559,7 @@ def diff_full(obj1 = 'HEAD', obj2 = nil, opts = {})
553
559
end
554
560
555
561
def diff_stats ( obj1 = 'HEAD' , obj2 = nil , opts = { } )
556
- validate_no_options ( 'commit or commit range' , obj1 , obj2 )
562
+ assert_args_are_not_options ( 'commit or commit range' , obj1 , obj2 )
557
563
558
564
diff_opts = [ '--numstat' ]
559
565
diff_opts << obj1
@@ -575,7 +581,7 @@ def diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {})
575
581
end
576
582
577
583
def diff_name_status ( reference1 = nil , reference2 = nil , opts = { } )
578
- validate_no_options ( 'commit or commit range' , reference1 , reference2 )
584
+ assert_args_are_not_options ( 'commit or commit range' , reference1 , reference2 )
579
585
580
586
opts_arr = [ '--name-status' ]
581
587
opts_arr << reference1 if reference1
0 commit comments