@@ -37,7 +37,7 @@ def init(opts={})
37
37
arr_opts = [ ]
38
38
arr_opts << '--bare' if opts [ :bare ]
39
39
40
- command ( 'init' , arr_opts , false )
40
+ command ( 'init' , arr_opts , chdir : false )
41
41
end
42
42
43
43
# tries to clone the given repo
@@ -132,7 +132,7 @@ def log_commits(opts={})
132
132
133
133
arr_opts += log_path_options ( opts )
134
134
135
- command_lines ( 'log' , arr_opts , true ) . map { |l | l . split . first }
135
+ command_lines ( 'log' , arr_opts , chdir : true ) . map { |l | l . split . first }
136
136
end
137
137
138
138
def full_log_commits ( opts = { } )
@@ -143,7 +143,7 @@ def full_log_commits(opts={})
143
143
144
144
arr_opts += log_path_options ( opts )
145
145
146
- full_log = command_lines ( 'log' , arr_opts , true )
146
+ full_log = command_lines ( 'log' , arr_opts , chdir : true )
147
147
148
148
process_commit_log_data ( full_log )
149
149
end
@@ -411,7 +411,7 @@ def ls_files(location=nil)
411
411
def ls_remote ( location = nil )
412
412
location ||= '.'
413
413
Hash . new { |h , k | h [ k ] = { } } . tap do |hsh |
414
- command_lines ( 'ls-remote' , [ location ] , false ) . each do |line |
414
+ command_lines ( 'ls-remote' , [ location ] , chdir : false ) . each do |line |
415
415
( sha , info ) = line . split ( "\t " )
416
416
( ref , type , name ) = info . split ( '/' , 3 )
417
417
type ||= 'head'
@@ -450,7 +450,7 @@ def config_get(name)
450
450
end
451
451
452
452
def global_config_get ( name )
453
- command ( 'config' , [ '--global' , '--get' , name ] , false )
453
+ command ( 'config' , [ '--global' , '--get' , name ] , chdir : false )
454
454
end
455
455
456
456
def config_list
@@ -466,7 +466,7 @@ def config_list
466
466
end
467
467
468
468
def global_config_list
469
- parse_config_list command_lines ( 'config' , [ '--global' , '--list' ] , false )
469
+ parse_config_list command_lines ( 'config' , [ '--global' , '--list' ] , chdir : false )
470
470
end
471
471
472
472
def parse_config_list ( lines )
@@ -479,7 +479,7 @@ def parse_config_list(lines)
479
479
end
480
480
481
481
def parse_config ( file )
482
- parse_config_list command_lines ( 'config' , [ '--list' , '--file' , file ] , false )
482
+ parse_config_list command_lines ( 'config' , [ '--list' , '--file' , file ] , chdir : false )
483
483
end
484
484
485
485
# Shows objects
@@ -502,7 +502,7 @@ def config_set(name, value)
502
502
end
503
503
504
504
def global_config_set ( name , value )
505
- command ( 'config' , [ '--global' , name , value ] , false )
505
+ command ( 'config' , [ '--global' , name , value ] , chdir : false )
506
506
end
507
507
508
508
# updates the repository index using the working directory content
@@ -671,10 +671,10 @@ def unmerged
671
671
def conflicts # :yields: file, your, their
672
672
self . unmerged . each do |f |
673
673
your = Tempfile . new ( "YOUR-#{ File . basename ( f ) } " ) . path
674
- command ( 'show' , ":2:#{ f } " , true , "> #{ escape your } " )
674
+ command ( 'show' , ":2:#{ f } " , chdir : true , redirect : "> #{ escape your } " )
675
675
676
676
their = Tempfile . new ( "THEIR-#{ File . basename ( f ) } " ) . path
677
- command ( 'show' , ":3:#{ f } " , true , "> #{ escape their } " )
677
+ command ( 'show' , ":3:#{ f } " , chdir : true , redirect : "> #{ escape their } " )
678
678
yield ( f , your , their )
679
679
end
680
680
end
@@ -799,7 +799,7 @@ def commit_tree(tree, opts = {})
799
799
arr_opts << tree
800
800
arr_opts << '-p' << opts [ :parent ] if opts [ :parent ]
801
801
arr_opts += [ opts [ :parents ] ] . map { |p | [ '-p' , p ] } . flatten if opts [ :parents ]
802
- command ( 'commit-tree' , arr_opts , true , "< #{ escape t . path } " )
802
+ command ( 'commit-tree' , arr_opts , chdir : true , redirect : "< #{ escape t . path } " )
803
803
end
804
804
805
805
def update_ref ( branch , commit )
@@ -845,13 +845,13 @@ def archive(sha, file = nil, opts = {})
845
845
arr_opts << "--remote=#{ opts [ :remote ] } " if opts [ :remote ]
846
846
arr_opts << sha
847
847
arr_opts << '--' << opts [ :path ] if opts [ :path ]
848
- command ( 'archive' , arr_opts , true , ( opts [ :add_gzip ] ? '| gzip' : '' ) + " > #{ escape file } " )
848
+ command ( 'archive' , arr_opts , chdir : true , redirect : ( opts [ :add_gzip ] ? '| gzip' : '' ) + " > #{ escape file } " )
849
849
return file
850
850
end
851
851
852
852
# returns the current version of git, as an Array of Fixnums.
853
853
def current_command_version
854
- output = command ( 'version' , [ ] , false )
854
+ output = command ( 'version' , [ ] , chdir : false )
855
855
version = output [ /\d +\. \d +(\. \d +)+/ ]
856
856
version . split ( '.' ) . collect { |i | i . to_i }
857
857
end
@@ -872,8 +872,8 @@ def meets_required_version?
872
872
# @return [<String>] the names of the EVN variables involved in the git commands
873
873
ENV_VARIABLE_NAMES = [ 'GIT_DIR' , 'GIT_WORK_TREE' , 'GIT_INDEX_FILE' , 'GIT_SSH' ]
874
874
875
- def command_lines ( cmd , opts = [ ] , chdir = true , redirect = '' )
876
- cmd_op = command ( cmd , opts , chdir )
875
+ def command_lines ( cmd , * opts )
876
+ cmd_op = command ( cmd , * opts )
877
877
if cmd_op . encoding . name != "UTF-8"
878
878
op = cmd_op . encode ( "UTF-8" , "binary" , {
879
879
:invalid => :replace ,
@@ -922,7 +922,18 @@ def with_custom_env_variables(&block)
922
922
restore_git_system_env_variables ( )
923
923
end
924
924
925
- def command ( cmd , opts = [ ] , chdir = true , redirect = '' , &block )
925
+ def command ( cmd , *opts , &block )
926
+ command_opts = { chdir : true , redirect : '' }
927
+ if opts . last . is_a? ( Hash )
928
+ command_opts . merge! ( opts . pop )
929
+ end
930
+ command_opts . keys . each do |k |
931
+ raise ArgumentError . new ( "Unsupported option: #{ k } " ) unless %i[ chdir redirect ] . include? ( k )
932
+ end
933
+
934
+ default_command_opts = { chdir : true , redirect : '' }
935
+ command_opts = default_command_opts . merge ( command_opts )
936
+
926
937
global_opts = [ ]
927
938
global_opts << "--git-dir=#{ @git_dir } " if !@git_dir . nil?
928
939
global_opts << "--work-tree=#{ @git_work_dir } " if !@git_work_dir . nil?
@@ -931,7 +942,7 @@ def command(cmd, opts = [], chdir = true, redirect = '', &block)
931
942
932
943
global_opts = global_opts . flatten . map { |s | escape ( s ) } . join ( ' ' )
933
944
934
- git_cmd = "#{ Git ::Base . config . binary_path } #{ global_opts } #{ cmd } #{ opts } #{ redirect } 2>&1"
945
+ git_cmd = "#{ Git ::Base . config . binary_path } #{ global_opts } #{ cmd } #{ opts } #{ command_opts [ : redirect] } 2>&1"
935
946
936
947
output = nil
937
948
0 commit comments