Skip to content

Support multiple --config options in Git.clone #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
3 changes: 2 additions & 1 deletion lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 12 additions & 1 deletion tests/units/test_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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
Expand Down