diff --git a/CHANGELOG.md b/CHANGELOG.md index 786e589..78cc0af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,10 @@ ##### Bug Fixes -* None. +* Force encode branch name to properly clone it. + [xdkhan](https://github.com/xdkhan) + [Dimitris Koutsogiorgas](https://github.com/dnkoutso) + [#116](https://github.com/CocoaPods/cocoapods-downloader/pull/116) ## 1.4.0 (2020-07-17) diff --git a/lib/cocoapods-downloader/git.rb b/lib/cocoapods-downloader/git.rb index 307e6d0..f7914e6 100644 --- a/lib/cocoapods-downloader/git.rb +++ b/lib/cocoapods-downloader/git.rb @@ -52,7 +52,8 @@ def self.preprocess_options(options) # def self.commit_from_ls_remote(output, branch_name) return nil if branch_name.nil? - match = %r{([a-z0-9]*)\trefs\/(heads|tags)\/#{Regexp.quote(branch_name)}}.match(output) + encoded_branch_name = branch_name.force_encoding(Encoding::ASCII_8BIT) + match = %r{([a-z0-9]*)\trefs\/(heads|tags)\/#{Regexp.quote(encoded_branch_name)}}.match(output) match[1] unless match.nil? end diff --git a/spec/git_spec.rb b/spec/git_spec.rb index d518f59..bafea00 100644 --- a/spec/git_spec.rb +++ b/spec/git_spec.rb @@ -26,6 +26,13 @@ def fixture_url(name) tmp_folder('README').read.strip.should == 'topic_branch' end + it 'checks out a specific branch with forced encoding' do + options = { :git => fixture('git-repo'), :branch => '中文分支' } + downloader = Downloader.for_target(tmp_folder, options) + downloader.download + tmp_folder('README').read.strip.should == '中文分支' + end + it 'checks out a specific tag' do options = { :git => fixture('git-repo'), :tag => 'v1.0' } downloader = Downloader.for_target(tmp_folder, options)