Skip to content

Commit c3a91bb

Browse files
committed
Add: Support multiple --config options in clone
Makes opts[:config] in Git.clone accept an Array of <key>=<value> pairs so that multiple --config options can be passed to the clone command. A single config entry can still be passed as a String. Signed-off-by: Marco Rüdisüli <git@rudisu.li>
1 parent 4bef5ab commit c3a91bb

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ And here are the operations that will need to write to your git repository.
169169
{ :repository => '/opt/git/proj.git',
170170
:index => '/tmp/index'} )
171171

172-
g = Git.clone(URI, NAME, :path => '/tmp/checkout')
172+
g = Git.clone(URI, NAME, :path => '/tmp/checkout', :config => [
173+
'core.sshCommand=ssh -i /home/user/.ssh/id_rsa',
174+
'submodule.recurse=true'])
173175
g.config('user.name', 'Scott Chacon')
174176
g.config('user.email', 'email@email.com')
175177

lib/git/lib.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def clone(repository, name, opts = {})
6565
arr_opts << '--bare' if opts[:bare]
6666
arr_opts << '--branch' << opts[:branch] if opts[:branch]
6767
arr_opts << '--depth' << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0
68-
arr_opts << '--config' << opts[:config] if opts[:config]
68+
arr_opts << '--config' << opts[:config] if opts[:config] && opts[:config].is_a?(String)
69+
opts[:config].each { |c| arr_opts << '--config' << c } if opts[:config].is_a?(Array)
6970
arr_opts << '--origin' << opts[:remote] || opts[:origin] if opts[:remote] || opts[:origin]
7071
arr_opts << '--recursive' if opts[:recursive]
7172
arr_opts << "--mirror" if opts[:mirror]

tests/units/test_init.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_git_clone_mirror
9090
end
9191
end
9292

93-
def test_git_clone_config
93+
def test_git_clone_config_single
9494
in_temp_dir do |path|
9595
g = Git.clone(@wbare, 'config.git', :config => "receive.denyCurrentBranch=ignore")
9696
assert_equal('ignore', g.config['receive.denycurrentbranch'])
@@ -99,6 +99,17 @@ def test_git_clone_config
9999
end
100100
end
101101

102+
def test_git_clone_config_multi
103+
conf = ["receive.denyCurrentBranch=ignore", "submodule.recurse=true"]
104+
in_temp_dir do |path|
105+
g = Git.clone(@wbare, 'config.git', :config => conf)
106+
assert_equal('ignore', g.config['receive.denycurrentbranch'])
107+
assert_equal('true', g.config['submodule.recurse'])
108+
assert(File.exist?(File.join(g.repo.path, 'config')))
109+
assert(g.dir)
110+
end
111+
end
112+
102113
# trying to open a git project using a bare repo - rather than using Git.repo
103114
def test_git_open_error
104115
assert_raise ArgumentError do

0 commit comments

Comments
 (0)