diff --git a/lib/git/lib.rb b/lib/git/lib.rb index f1bd6439..54f7a127 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -57,6 +57,7 @@ def clone(repository, name, opts = {}) arr_opts = [] arr_opts << "--bare" if opts[:bare] + arr_opts << "--mirror" if opts[:mirror] arr_opts << "--recursive" if opts[:recursive] arr_opts << "-o" << opts[:remote] if opts[:remote] arr_opts << "--depth" << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0 @@ -68,7 +69,7 @@ def clone(repository, name, opts = {}) command('clone', arr_opts) - opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir} + (opts[:bare] or opts[:mirror]) ? {:repository => clone_dir} : {:working_directory => clone_dir} end @@ -616,14 +617,19 @@ def fetch(remote, opts) def push(remote, branch = 'master', opts = {}) # Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature. - opts = {:tags => opts} if [true, false].include?(opts) + opts = {:tags => opts} if [true, false].include?(opts) arr_opts = [] + arr_opts << '--mirror' if opts[:mirror] arr_opts << '--force' if opts[:force] || opts[:f] arr_opts << remote - command('push', arr_opts + [branch]) - command('push', ['--tags'] + arr_opts) if opts[:tags] + if opts[:mirror] + command('push', arr_opts) + else + command('push', arr_opts + [branch]) + command('push', ['--tags'] + arr_opts) if opts[:tags] + end end def pull(remote='origin', branch='master') diff --git a/tests/units/test_init.rb b/tests/units/test_init.rb index d735791d..01821278 100644 --- a/tests/units/test_init.rb +++ b/tests/units/test_init.rb @@ -75,6 +75,14 @@ def test_git_clone_bare end end + def test_git_clone_mirror + in_temp_dir do |path| + g = Git.clone(@wbare, 'bare.git', :mirror => true) + assert(File.exist?(File.join(g.repo.path, 'config'))) + assert_nil(g.dir) + end + end + def test_git_clone_config in_temp_dir do |path| g = Git.clone(@wbare, 'config.git', :config => "receive.denyCurrentBranch=ignore")