@@ -526,7 +526,24 @@ def grep(string, opts = {})
526
526
hsh
527
527
end
528
528
529
+ # Validate that the given arguments cannot be mistaken for a command-line option
530
+ #
531
+ # @param arg_name [String] the name of the arguments to mention in the error message
532
+ # @param args [Array<String, nil>] the arguments to validate
533
+ #
534
+ # @raise [ArgumentError] if any of the parameters are a string starting with a hyphen
535
+ # @return [void]
536
+ #
537
+ def validate_no_options ( arg_name , *args )
538
+ invalid_args = args . select { |arg | arg &.start_with? ( '-' ) }
539
+ if invalid_args . any?
540
+ raise ArgumentError , "Invalid #{ arg_name } : '#{ invalid_args . join ( "', '" ) } '"
541
+ end
542
+ end
543
+
529
544
def diff_full ( obj1 = 'HEAD' , obj2 = nil , opts = { } )
545
+ validate_no_options ( 'commit or commit range' , obj1 , obj2 )
546
+
530
547
diff_opts = [ '-p' ]
531
548
diff_opts << obj1
532
549
diff_opts << obj2 if obj2 . is_a? ( String )
@@ -536,6 +553,8 @@ def diff_full(obj1 = 'HEAD', obj2 = nil, opts = {})
536
553
end
537
554
538
555
def diff_stats ( obj1 = 'HEAD' , obj2 = nil , opts = { } )
556
+ validate_no_options ( 'commit or commit range' , obj1 , obj2 )
557
+
539
558
diff_opts = [ '--numstat' ]
540
559
diff_opts << obj1
541
560
diff_opts << obj2 if obj2 . is_a? ( String )
@@ -556,6 +575,8 @@ def diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {})
556
575
end
557
576
558
577
def diff_name_status ( reference1 = nil , reference2 = nil , opts = { } )
578
+ validate_no_options ( 'commit or commit range' , reference1 , reference2 )
579
+
559
580
opts_arr = [ '--name-status' ]
560
581
opts_arr << reference1 if reference1
561
582
opts_arr << reference2 if reference2
0 commit comments