From f8df52f5fdd7278e0c5a4007f852a6c3b3fe015a Mon Sep 17 00:00:00 2001 From: "dimo.hamdy" Date: Tue, 10 Aug 2021 22:46:34 +0200 Subject: [PATCH 1/2] Fix bug of Git shallow cloning is not used when branch is set --- lib/cocoapods-downloader/git.rb | 5 ++++- spec/git_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/cocoapods-downloader/git.rb b/lib/cocoapods-downloader/git.rb index f7914e6..18e9a94 100644 --- a/lib/cocoapods-downloader/git.rb +++ b/lib/cocoapods-downloader/git.rb @@ -32,7 +32,6 @@ def self.preprocess_options(options) return options if match.nil? options[:commit] = match - options.delete(:branch) options end @@ -134,6 +133,10 @@ def clone_arguments(force_head, shallow_clone) command += %w(--single-branch --depth 1) end + if shallow_clone && options[:commit] && options[:branch] + command += %w(--single-branch --depth 1) + end + unless force_head if tag_or_branch = options[:tag] || options[:branch] command += ['--branch', tag_or_branch] diff --git a/spec/git_spec.rb b/spec/git_spec.rb index bafea00..84eceaa 100644 --- a/spec/git_spec.rb +++ b/spec/git_spec.rb @@ -222,6 +222,30 @@ def ensure_only_one_ref(folder) should.not.raise { downloader.download } end end + + describe 'get remote default branch if not set branch with shallow clones' do + it 'with git <= 2.10.x' do + options = { :git => fixture_url('git-repo') } + downloader = Downloader.for_target(tmp_folder, options) + message = '/usr/local/bin/git clone URL directory --single-branch ' \ + "--depth 1\nCloning into 'directory'...\n" \ + 'fatal: dumb http transport does not support --depth' + dumb_remote_error = Pod::Downloader::DownloaderError.new(message) + downloader.stubs(:git!).raises(dumb_remote_error).then.returns(true) + should.not.raise { downloader.download } + end + + it 'with git >= 2.11.x' do + options = { :git => fixture_url('git-repo') } + downloader = Downloader.for_target(tmp_folder, options) + message = '/usr/local/bin/git clone URL directory --single-branch ' \ + "--depth 1\nCloning into 'directory'...\n" \ + 'fatal: dumb http transport does not support shallow capabilities' + dumb_remote_error = Pod::Downloader::DownloaderError.new(message) + downloader.stubs(:git!).raises(dumb_remote_error).then.returns(true) + should.not.raise { downloader.download } + end + end end describe ':commit_from_ls_remote' do From 4cd3db4f09937c2a4718c0264e041f0a2edfaf5a Mon Sep 17 00:00:00 2001 From: "dimo.hamdy" Date: Tue, 10 Aug 2021 22:52:55 +0200 Subject: [PATCH 2/2] Update change log --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78cc0af..f902200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ [xdkhan](https://github.com/xdkhan) [Dimitris Koutsogiorgas](https://github.com/dnkoutso) [#116](https://github.com/CocoaPods/cocoapods-downloader/pull/116) + +* Fix bug of Git shallow cloning is not used when branch is set. + [Dimo Hamdy](https://github.com/dimohamdy) + [Pavel](https://github.com/paiv) + [#106](https://github.com/CocoaPods/cocoapods-downloader/issues/106) ## 1.4.0 (2020-07-17)