Skip to content

Add support for unshallow #303

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 10 commits into from
5 changes: 4 additions & 1 deletion lib/git/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def self.bare(git_dir, opts = {})
#
def self.clone(repository, name, opts = {})
# run git-clone
self.new(Git::Lib.new.clone(repository, name, opts))
self.new(Git::Lib.new(env: opts.delete(:env)).clone(repository, name, opts))
end

# Returns (and initialize if needed) a Git::Config instance
Expand Down Expand Up @@ -75,6 +75,8 @@ def self.open(working_dir, opts={})
self.new({:working_directory => working_dir}.merge(opts))
end

attr_reader :env

def initialize(options = {})
if working_dir = options[:working_directory]
options[:repository] ||= File.join(working_dir, '.git')
Expand All @@ -90,6 +92,7 @@ def initialize(options = {})
@working_directory = options[:working_directory] ? Git::WorkingDirectory.new(options[:working_directory]) : nil
@repository = options[:repository] ? Git::Repository.new(options[:repository]) : nil
@index = options[:index] ? Git::Index.new(options[:index], false) : nil
@env = (options[:env] || {}).freeze
end

# changes current working directory for a block
Expand Down
18 changes: 14 additions & 4 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ def initialize(base = nil, logger = nil)
@git_dir = base.repo.path
@git_index_file = base.index.path if base.index
@git_work_dir = base.dir.path if base.dir
@git_extra_env = base.env
elsif base.is_a?(Hash)
@git_dir = base[:repository]
@git_index_file = base[:index]
@git_work_dir = base[:working_directory]
@git_extra_env = base[:env].freeze
end
@git_extra_env ||= {}.freeze
@logger = logger
end

Expand Down Expand Up @@ -64,6 +67,7 @@ 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 << '--no-single-branch' if opts[:no_single_branch]
arr_opts << '--config' << opts[:config] if opts[:config]
arr_opts << '--origin' << opts[:remote] || opts[:origin] if opts[:remote] || opts[:origin]
arr_opts << '--recursive' if opts[:recursive]
Expand All @@ -75,7 +79,7 @@ def clone(repository, name, opts = {})

command('clone', arr_opts)

opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir}
opts[:bare] ? {:repository => clone_dir} : {:working_directory => clone_dir, :env => @git_extra_env}
end


Expand Down Expand Up @@ -577,6 +581,7 @@ def revert(commitish, opts = {})

arr_opts = []
arr_opts << '--no-edit' if opts[:no_edit]
arr_opts << '--no-commit' if opts[:no_commit]
arr_opts << commitish

command('revert', arr_opts)
Expand Down Expand Up @@ -725,8 +730,10 @@ def tag(name, *opts)

def fetch(remote, opts)
arr_opts = [remote]
arr_opts << opts[:refs] if opts[:refs]
arr_opts << '--tags' if opts[:t] || opts[:tags]
arr_opts << '--prune' if opts[:p] || opts[:prune]
arr_opts << '--unshallow' if opts[:unshallow]

command('fetch', arr_opts)
end
Expand Down Expand Up @@ -850,7 +857,7 @@ def meets_required_version?
end


private
protected

# Systen ENV variables involved in the git commands.
#
Expand All @@ -869,14 +876,14 @@ def command_lines(cmd, opts = [], chdir = true, redirect = '')
# Takes the current git's system ENV variables and store them.
def store_git_system_env_variables
@git_system_env_variables = {}
ENV_VARIABLE_NAMES.each do |env_variable_name|
(ENV_VARIABLE_NAMES + @git_extra_env.keys).each do |env_variable_name|
@git_system_env_variables[env_variable_name] = ENV[env_variable_name]
end
end

# Takes the previously stored git's ENV variables and set them again on ENV.
def restore_git_system_env_variables
ENV_VARIABLE_NAMES.each do |env_variable_name|
(ENV_VARIABLE_NAMES + @git_extra_env.keys).each do |env_variable_name|
ENV[env_variable_name] = @git_system_env_variables[env_variable_name]
end
end
Expand All @@ -887,6 +894,9 @@ def set_custom_git_env_variables
ENV['GIT_WORK_TREE'] = @git_work_dir
ENV['GIT_INDEX_FILE'] = @git_index_file
ENV['GIT_SSH'] = Git::Base.config.git_ssh
@git_extra_env.each do |k, v|
ENV[k] = v
end
end

# Runs a block inside an environment with customized ENV variables.
Expand Down