Skip to content

Commit 917a56f

Browse files
Enable mirror option for git clone and push.
c.f. https://help.github.com/articles/duplicating-a-repository
1 parent 8425a6b commit 917a56f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/git/lib.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def clone(repository, name, opts = {})
5757

5858
arr_opts = []
5959
arr_opts << "--bare" if opts[:bare]
60+
arr_opts << "--mirror" if opts[:mirror]
6061
arr_opts << "--recursive" if opts[:recursive]
6162
arr_opts << "-o" << opts[:remote] if opts[:remote]
6263
arr_opts << "--depth" << opts[:depth].to_i if opts[:depth] && opts[:depth].to_i > 0
@@ -68,7 +69,7 @@ def clone(repository, name, opts = {})
6869

6970
command('clone', arr_opts)
7071

71-
opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir}
72+
(opts[:bare] or opts[:mirror]) ? {:repository => clone_dir} : {:working_directory => clone_dir}
7273
end
7374

7475

@@ -616,14 +617,19 @@ def fetch(remote, opts)
616617

617618
def push(remote, branch = 'master', opts = {})
618619
# Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature.
619-
opts = {:tags => opts} if [true, false].include?(opts)
620+
opts = {:tags => opts} if [true, false].include?(opts)
620621

621622
arr_opts = []
623+
arr_opts << '--mirror' if opts[:mirror]
622624
arr_opts << '--force' if opts[:force] || opts[:f]
623625
arr_opts << remote
624626

625-
command('push', arr_opts + [branch])
626-
command('push', ['--tags'] + arr_opts) if opts[:tags]
627+
if opts[:mirror]
628+
command('push', arr_opts)
629+
else
630+
command('push', arr_opts + [branch])
631+
command('push', ['--tags'] + arr_opts) if opts[:tags]
632+
end
627633
end
628634

629635
def pull(remote='origin', branch='master')

tests/units/test_init.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def test_git_clone_bare
7575
end
7676
end
7777

78+
def test_git_clone_mirror
79+
in_temp_dir do |path|
80+
g = Git.clone(@wbare, 'bare.git', :mirror => true)
81+
assert(File.exist?(File.join(g.repo.path, 'config')))
82+
assert_nil(g.dir)
83+
end
84+
end
85+
7886
def test_git_clone_config
7987
in_temp_dir do |path|
8088
g = Git.clone(@wbare, 'config.git', :config => "receive.denyCurrentBranch=ignore")

0 commit comments

Comments
 (0)