diff --git a/README.markdown b/README.markdown index 1dd0841..eca389f 100644 --- a/README.markdown +++ b/README.markdown @@ -29,6 +29,7 @@ The downloader class supports the following option keys: - git: commit, tag, branch, submodules - hg: revision +- bzr: revision, tag - svn: revision, tag, folder - http: type diff --git a/lib/cocoapods-downloader.rb b/lib/cocoapods-downloader.rb index aa534f0..d80fe19 100644 --- a/lib/cocoapods-downloader.rb +++ b/lib/cocoapods-downloader.rb @@ -16,12 +16,14 @@ def self.downloader_class_by_key require 'cocoapods-downloader/mercurial' require 'cocoapods-downloader/subversion' require 'cocoapods-downloader/http' + require 'cocoapods-downloader/bazaar' { :git => Git, :hg => Mercurial, :svn => Subversion, :http => Http, + :bzr => Bazaar, } end diff --git a/lib/cocoapods-downloader/bazaar.rb b/lib/cocoapods-downloader/bazaar.rb new file mode 100644 index 0000000..6ecf8e1 --- /dev/null +++ b/lib/cocoapods-downloader/bazaar.rb @@ -0,0 +1,52 @@ +module Pod + module Downloader + class Bazaar < Base + + def self.options + [:revision, :tag] + end + + def options_specific? + !options[:revision].nil? + end + + def checkout_options + Dir.chdir(target_path) do + options = {} + options[:bzr] = url + options[:revision] = `bzr revno`.chomp + options + end + end + + private + + executable :bzr + + def download! + if options[:tag] + download_revision!(options[:tag]) + elsif options[:revision] + download_revision!(options[:revision]) + else + download_head! + end + end + + def download_head! + bzr! %|branch "#{url}" #{dir_opts} "#{target_path}"| + end + + def download_revision!(rev) + bzr! %|branch "#{url}" #{dir_opts} -r '#{rev}' "#{target_path}"| + end + + def dir_opts + return '--use-existing-dir' if @target_path.exist? + '' + end + + end + end +end + diff --git a/spec/cocoapods-downloaders/bazaar_spec.rb b/spec/cocoapods-downloaders/bazaar_spec.rb new file mode 100644 index 0000000..4b1f3a3 --- /dev/null +++ b/spec/cocoapods-downloaders/bazaar_spec.rb @@ -0,0 +1,61 @@ +require File.expand_path('../../spec_helper', __FILE__) + +module Pod + module Downloader + describe 'Bazaar' do + + before do + tmp_folder.rmtree if tmp_folder.exist? + end + + it 'checks out a specific revision' do + options = { :bzr => fixture('bazaar-repo'), :revision => '1' } + downloader = Downloader.for_target(tmp_folder, options) + downloader.download + tmp_folder('README').read.strip.should == 'First Commit' + end + + it 'checks out a specific tag as a revision' do + options = { :bzr => fixture('bazaar-repo'), :revision => 'my_tag' } + downloader = Downloader.for_target(tmp_folder, options) + downloader.download + tmp_folder('README').read.strip.should == 'Second Commit' + end + + it 'checks out a specific tag as a tag' do + options = { :bzr => fixture('bazaar-repo'), :tag => 'my_other_tag' } + downloader = Downloader.for_target(tmp_folder, options) + downloader.download + tmp_folder('README').read.strip.should == 'Third Commit' + end + + it 'checks out the head revision' do + options = { :bzr => fixture('bazaar-repo') } + downloader = Downloader.for_target(tmp_folder, options) + downloader.download + tmp_folder('README').read.strip.should == 'Fourth Commit' + end + + it 'returns the checked out revision' do + options = { :bzr => fixture('bazaar-repo') } + downloader = Downloader.for_target(tmp_folder, options) + downloader.download + downloader.checkout_options.should == { + :bzr => fixture('bazaar-repo'), + :revision => '4' + } + end + + it 'returns whether the provided options are specific' do + Downloader.for_target('path', :bzr => 'url').options_specific?.should.be.false + Downloader.for_target('path', :bzr => 'url', :revision => '').options_specific?.should.be.true + end + + it 'raises if it fails to download' do + options = { :bzr => 'missing-repo', :revision => '12' } + downloader = Downloader.for_target(tmp_folder, options) + lambda { downloader.download }.should.raise DownloaderError + end + end + end +end diff --git a/spec/fixtures/bazaar-repo/.bzr/README b/spec/fixtures/bazaar-repo/.bzr/README new file mode 100644 index 0000000..f82dc1c --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/README @@ -0,0 +1,3 @@ +This is a Bazaar control directory. +Do not change any files in this directory. +See http://bazaar.canonical.com/ for more information about Bazaar. diff --git a/spec/fixtures/bazaar-repo/.bzr/branch-format b/spec/fixtures/bazaar-repo/.bzr/branch-format new file mode 100644 index 0000000..9eb09b7 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/branch-format @@ -0,0 +1 @@ +Bazaar-NG meta directory, format 1 diff --git a/spec/fixtures/bazaar-repo/.bzr/branch/branch.conf b/spec/fixtures/bazaar-repo/.bzr/branch/branch.conf new file mode 100644 index 0000000..e69de29 diff --git a/spec/fixtures/bazaar-repo/.bzr/branch/format b/spec/fixtures/bazaar-repo/.bzr/branch/format new file mode 100644 index 0000000..dc392f4 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/branch/format @@ -0,0 +1 @@ +Bazaar Branch Format 7 (needs bzr 1.6) diff --git a/spec/fixtures/bazaar-repo/.bzr/branch/last-revision b/spec/fixtures/bazaar-repo/.bzr/branch/last-revision new file mode 100644 index 0000000..b160a44 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/branch/last-revision @@ -0,0 +1 @@ +4 fred@sharpnoodles.com-20130903122427-q62tvv61aw0v4f4m diff --git a/spec/fixtures/bazaar-repo/.bzr/branch/tags b/spec/fixtures/bazaar-repo/.bzr/branch/tags new file mode 100644 index 0000000..dd97f9d --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/branch/tags @@ -0,0 +1 @@ +d12:my_other_tag53:fred@sharpnoodles.com-20130903122403-19amncmj76umtisz6:my_tag53:fred@sharpnoodles.com-20130903122345-4ladk888amaey5uxe \ No newline at end of file diff --git a/spec/fixtures/bazaar-repo/.bzr/checkout/conflicts b/spec/fixtures/bazaar-repo/.bzr/checkout/conflicts new file mode 100644 index 0000000..0dc2d3a --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/checkout/conflicts @@ -0,0 +1 @@ +BZR conflict list format 1 diff --git a/spec/fixtures/bazaar-repo/.bzr/checkout/dirstate b/spec/fixtures/bazaar-repo/.bzr/checkout/dirstate new file mode 100644 index 0000000..2fd044d Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/checkout/dirstate differ diff --git a/spec/fixtures/bazaar-repo/.bzr/checkout/format b/spec/fixtures/bazaar-repo/.bzr/checkout/format new file mode 100644 index 0000000..e0261c7 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/checkout/format @@ -0,0 +1 @@ +Bazaar Working Tree Format 6 (bzr 1.14) diff --git a/spec/fixtures/bazaar-repo/.bzr/checkout/views b/spec/fixtures/bazaar-repo/.bzr/checkout/views new file mode 100644 index 0000000..e69de29 diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/format b/spec/fixtures/bazaar-repo/.bzr/repository/format new file mode 100644 index 0000000..b200528 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/repository/format @@ -0,0 +1 @@ +Bazaar repository format 2a (needs bzr 1.16 or later) diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.cix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.cix new file mode 100644 index 0000000..37eb0db Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.cix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.iix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.iix new file mode 100644 index 0000000..8d6b85e Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.iix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.rix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.rix new file mode 100644 index 0000000..4e3dfac --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.rix @@ -0,0 +1,6 @@ +B+Tree Graph Index 2 +node_ref_lists=1 +key_elements=1 +len=1 +row_lengths=1 +xQ@0@=E/@h|H\"A7ܟp*\<i1;jG 2:p_ۺVELI' \ No newline at end of file diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.six b/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.six new file mode 100644 index 0000000..a2afde6 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.six @@ -0,0 +1,5 @@ +B+Tree Graph Index 2 +node_ref_lists=0 +key_elements=1 +len=0 +row_lengths= diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.tix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.tix new file mode 100644 index 0000000..f6603e1 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/0eee32389584c19d27fb19f04c01564d.tix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.cix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.cix new file mode 100644 index 0000000..9f85706 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.cix @@ -0,0 +1,6 @@ +B+Tree Graph Index 2 +node_ref_lists=0 +key_elements=1 +len=1 +row_lengths=1 +x 0 ԙ"#3q&[Hа=wwqY"e13\Y̘ڥIurIڢ' \ No newline at end of file diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.iix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.iix new file mode 100644 index 0000000..70c6756 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.iix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.rix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.rix new file mode 100644 index 0000000..07702ee Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.rix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.six b/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.six new file mode 100644 index 0000000..a2afde6 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.six @@ -0,0 +1,5 @@ +B+Tree Graph Index 2 +node_ref_lists=0 +key_elements=1 +len=0 +row_lengths= diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.tix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.tix new file mode 100644 index 0000000..22c8e72 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/16b1053ed12916f4f545020352384e52.tix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.cix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.cix new file mode 100644 index 0000000..ec69e75 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.cix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.iix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.iix new file mode 100644 index 0000000..35af968 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.iix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.rix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.rix new file mode 100644 index 0000000..ef8b2b3 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.rix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.six b/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.six new file mode 100644 index 0000000..a2afde6 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.six @@ -0,0 +1,5 @@ +B+Tree Graph Index 2 +node_ref_lists=0 +key_elements=1 +len=0 +row_lengths= diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.tix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.tix new file mode 100644 index 0000000..8c55dad Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/7ce6129415e312dba7c6ca36ee0f2157.tix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.cix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.cix new file mode 100644 index 0000000..481b0e8 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.cix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.iix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.iix new file mode 100644 index 0000000..b696a10 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.iix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.rix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.rix new file mode 100644 index 0000000..576e788 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.rix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.six b/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.six new file mode 100644 index 0000000..a2afde6 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.six @@ -0,0 +1,5 @@ +B+Tree Graph Index 2 +node_ref_lists=0 +key_elements=1 +len=0 +row_lengths= diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.tix b/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.tix new file mode 100644 index 0000000..85189b9 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/indices/f9604713d4ada772a21468a6846344b2.tix differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/pack-names b/spec/fixtures/bazaar-repo/.bzr/repository/pack-names new file mode 100644 index 0000000..f9082e9 --- /dev/null +++ b/spec/fixtures/bazaar-repo/.bzr/repository/pack-names @@ -0,0 +1,7 @@ +B+Tree Graph Index 2 +node_ref_lists=0 +key_elements=1 +len=4 +row_lengths=1 +xE;1 DQY +Xǖ3PEx>uűO&s],CZpC~Lju1]GZސAGk:GLC6ItއwuQ=ߥND 1 \ No newline at end of file diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/packs/0eee32389584c19d27fb19f04c01564d.pack b/spec/fixtures/bazaar-repo/.bzr/repository/packs/0eee32389584c19d27fb19f04c01564d.pack new file mode 100644 index 0000000..cb005aa Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/packs/0eee32389584c19d27fb19f04c01564d.pack differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/packs/16b1053ed12916f4f545020352384e52.pack b/spec/fixtures/bazaar-repo/.bzr/repository/packs/16b1053ed12916f4f545020352384e52.pack new file mode 100644 index 0000000..89251b6 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/packs/16b1053ed12916f4f545020352384e52.pack differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/packs/7ce6129415e312dba7c6ca36ee0f2157.pack b/spec/fixtures/bazaar-repo/.bzr/repository/packs/7ce6129415e312dba7c6ca36ee0f2157.pack new file mode 100644 index 0000000..1715513 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/packs/7ce6129415e312dba7c6ca36ee0f2157.pack differ diff --git a/spec/fixtures/bazaar-repo/.bzr/repository/packs/f9604713d4ada772a21468a6846344b2.pack b/spec/fixtures/bazaar-repo/.bzr/repository/packs/f9604713d4ada772a21468a6846344b2.pack new file mode 100644 index 0000000..ffefa84 Binary files /dev/null and b/spec/fixtures/bazaar-repo/.bzr/repository/packs/f9604713d4ada772a21468a6846344b2.pack differ diff --git a/spec/fixtures/bazaar-repo/README b/spec/fixtures/bazaar-repo/README new file mode 100644 index 0000000..95e72da --- /dev/null +++ b/spec/fixtures/bazaar-repo/README @@ -0,0 +1 @@ +Fourth Commit \ No newline at end of file diff --git a/spec/fixtures/mercurial-repo/.hg/cache/tags b/spec/fixtures/mercurial-repo/.hg/cache/tags new file mode 100644 index 0000000..37cc8a2 --- /dev/null +++ b/spec/fixtures/mercurial-repo/.hg/cache/tags @@ -0,0 +1,2 @@ +1 df97b9ee89577f2da1925154472888b2b57e971e +