From cbc14442c0cf237a9e4e28e2c5bfbfb1741d9005 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 2 Aug 2016 20:07:57 -0500 Subject: [PATCH 1/7] Add support for unshallow --- lib/git/lib.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 777e42ea..b3766cfc 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -727,6 +727,7 @@ def fetch(remote, opts) arr_opts = [remote] 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 From 887a2583bd47d59bf81bdc76d405ba325d8f4265 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Tue, 23 Aug 2016 14:00:07 -0400 Subject: [PATCH 2/7] Allow user to pass the no commit option --- lib/git/lib.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index b3766cfc..14efbd63 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -577,6 +577,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) From 50a3caf39532ffd4e07c61c074f93b6f8bb4da90 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sun, 20 Nov 2016 13:36:10 -0500 Subject: [PATCH 3/7] Support clone option --no-single-branch For shallow clones that can still see all branches. --- lib/git/lib.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 14efbd63..4008c08d 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -64,6 +64,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] From 7805c712897a02b842d3836f191fb98dc6a2313e Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Fri, 18 Nov 2016 12:52:35 -0500 Subject: [PATCH 4/7] Allow passing extra environment variables This allows env vars to be set only when needed, and in a thread-safe way (so long as only things run using the gem read the env vars in question). --- lib/git/base.rb | 5 ++++- lib/git/lib.rb | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/git/base.rb b/lib/git/base.rb index ad3e52ec..1f554e25 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -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 @@ -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') @@ -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 diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 14efbd63..4ea5548b 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -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 @@ -871,14 +874,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 @@ -889,6 +892,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. From 86143b08c639dd9c60f5bbcc6006e6da860d08ec Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sun, 20 Nov 2016 15:33:13 -0500 Subject: [PATCH 5/7] Allow specifying ref patterns to fetch Mostly useful when fetching from a specific URL. --- lib/git/lib.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 14efbd63..de713b06 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -726,6 +726,7 @@ 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] From 8e05fa68d95a693c1008d95ae85fb589e5426322 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sat, 3 Dec 2016 12:22:51 -0500 Subject: [PATCH 6/7] Get away, private --- lib/git/lib.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 33f20eaa..9b0e6ce5 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -857,7 +857,7 @@ def meets_required_version? end - private + protected # Systen ENV variables involved in the git commands. # From f18157f12583412726888b2daf6319c0e5ee85ed Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 15 Aug 2017 13:22:47 -0500 Subject: [PATCH 7/7] Pass through env from clone --- lib/git/lib.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 9b0e6ce5..4972be90 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -79,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