Skip to content

Enable mirror option for git clone and push. #167

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
14 changes: 10 additions & 4 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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')
Expand Down
8 changes: 8 additions & 0 deletions tests/units/test_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down