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) diff --git a/lib/cocoapods-downloader/git.rb b/lib/cocoapods-downloader/git.rb index 2013993..9ca5f5c 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] = target_git('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