From 02a3d314fe4f39bc408f6263b2a295df7c570356 Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Sat, 15 Oct 2016 18:54:07 +0200 Subject: [PATCH 1/4] [Git] Use git -C rather than Dir.chdir --- lib/cocoapods-downloader/git.rb | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/cocoapods-downloader/git.rb b/lib/cocoapods-downloader/git.rb index 2013993..0818431 100644 --- a/lib/cocoapods-downloader/git.rb +++ b/lib/cocoapods-downloader/git.rb @@ -13,13 +13,11 @@ def options_specific? end def checkout_options - Dir.chdir(target_path) do - options = {} - options[:git] = url - options[:commit] = `git rev-parse HEAD`.chomp - options[:submodules] = true if self.options[:submodules] - options - end + options = {} + options[:git] = url + options[:commit] = `git -C #{target_path} rev-parse HEAD`.chomp + options[:submodules] = true if self.options[:submodules] + options end def self.preprocess_options(options) @@ -92,9 +90,7 @@ def clone(force_head = false, shallow_clone = true) def update_submodules return unless options[:submodules] - Dir.chdir(target_path) do - git! %w(submodule update --init --recursive) - end + target_git %w(submodule update --init --recursive) end # The arguments to pass to `git` to clone the repo. @@ -128,10 +124,12 @@ def clone_arguments(force_head, shallow_clone) # Checks out a specific commit of the cloned repo. # def checkout_commit - Dir.chdir(target_path) do - git! 'checkout', '--quiet', options[:commit] - update_submodules - end + target_git 'checkout', '--quiet', options[:commit] + update_submodules + end + + def target_git(*args) + git!(['-C', target_path] + args) end end end From 9061fe995bf916a67763dbb996fdad9a89be21bc Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Sat, 15 Oct 2016 22:05:24 +0200 Subject: [PATCH 2/4] Quote path --- lib/cocoapods-downloader/git.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cocoapods-downloader/git.rb b/lib/cocoapods-downloader/git.rb index 0818431..13e7c03 100644 --- a/lib/cocoapods-downloader/git.rb +++ b/lib/cocoapods-downloader/git.rb @@ -15,7 +15,7 @@ def options_specific? def checkout_options options = {} options[:git] = url - options[:commit] = `git -C #{target_path} rev-parse HEAD`.chomp + options[:commit] = `git -C "#{target_path}" rev-parse HEAD`.chomp options[:submodules] = true if self.options[:submodules] options end From 14299341e2d447754cf72b76de9a6c9f0cabf351 Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Sat, 15 Oct 2016 22:07:06 +0200 Subject: [PATCH 3/4] Add CHANGELOG entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf1ad07..f495bb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,9 @@ ##### Bug Fixes -* None. +* Use `git -C` rather than `chdir`. + [Danielle Tomlinson](https://github.com/dantoml) + [#62](https://github.com/CocoaPods/cocoapods-downloader/pull/62) ## 1.1.1 (2016-08-30) From 31719bbec42ffbc916af663ebd7dbc36646e7562 Mon Sep 17 00:00:00 2001 From: Danielle Tomlinson Date: Sun, 16 Oct 2016 22:52:16 +0200 Subject: [PATCH 4/4] [Git] Use target_git rather than backticks --- lib/cocoapods-downloader/git.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cocoapods-downloader/git.rb b/lib/cocoapods-downloader/git.rb index 13e7c03..9ca5f5c 100644 --- a/lib/cocoapods-downloader/git.rb +++ b/lib/cocoapods-downloader/git.rb @@ -15,7 +15,7 @@ def options_specific? def checkout_options options = {} options[:git] = url - options[:commit] = `git -C "#{target_path}" rev-parse HEAD`.chomp + options[:commit] = target_git('rev-parse', 'HEAD').chomp options[:submodules] = true if self.options[:submodules] options end