diff --git a/README.md b/README.md index 20a63c59..be4b6750 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,9 @@ And here are the operations that will need to write to your git repository. { :repository => '/opt/git/proj.git', :index => '/tmp/index'} ) - g = Git.clone(URI, NAME, :path => '/tmp/checkout') + g = Git.clone(URI, NAME, :path => '/tmp/checkout', :config => [ + 'core.sshCommand=ssh -i /home/user/.ssh/id_rsa', + 'submodule.recurse=true']) g.config('user.name', 'Scott Chacon') g.config('user.email', 'email@email.com') diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 92d603bf..3e90f228 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -65,7 +65,8 @@ def clone(repository, name, opts = {}) arr_opts << '--bare' if opts[:bare] arr_opts << '--branch' << opts[:branch] if opts[:branch] arr_opts << '--depth' << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0 - arr_opts << '--config' << opts[:config] if opts[:config] + arr_opts << '--config' << opts[:config] if opts[:config] && opts[:config].is_a?(String) + opts[:config].each { |c| arr_opts << '--config' << c } if opts[:config].is_a?(Array) arr_opts << '--origin' << opts[:remote] || opts[:origin] if opts[:remote] || opts[:origin] arr_opts << '--recursive' if opts[:recursive] arr_opts << "--mirror" if opts[:mirror] diff --git a/tests/units/test_init.rb b/tests/units/test_init.rb index 964ab789..dff3f75f 100644 --- a/tests/units/test_init.rb +++ b/tests/units/test_init.rb @@ -90,7 +90,7 @@ def test_git_clone_mirror end end - def test_git_clone_config + def test_git_clone_config_single in_temp_dir do |path| g = Git.clone(@wbare, 'config.git', :config => "receive.denyCurrentBranch=ignore") assert_equal('ignore', g.config['receive.denycurrentbranch']) @@ -99,6 +99,17 @@ def test_git_clone_config end end + def test_git_clone_config_multi + conf = ["receive.denyCurrentBranch=ignore", "submodule.recurse=true"] + in_temp_dir do |path| + g = Git.clone(@wbare, 'config.git', :config => conf) + assert_equal('ignore', g.config['receive.denycurrentbranch']) + assert_equal('true', g.config['submodule.recurse']) + assert(File.exist?(File.join(g.repo.path, 'config'))) + assert(g.dir) + end + end + # trying to open a git project using a bare repo - rather than using Git.repo def test_git_open_error assert_raise ArgumentError do