Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bzr support #4

Merged
merged 5 commits into from
Sep 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/cocoapods-downloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 52 additions & 0 deletions lib/cocoapods-downloader/bazaar.rb
Original file line number Diff line number Diff line change
@@ -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

61 changes: 61 additions & 0 deletions spec/cocoapods-downloaders/bazaar_spec.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions spec/fixtures/bazaar-repo/.bzr/README
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions spec/fixtures/bazaar-repo/.bzr/branch-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bazaar-NG meta directory, format 1
Empty file.
1 change: 1 addition & 0 deletions spec/fixtures/bazaar-repo/.bzr/branch/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bazaar Branch Format 7 (needs bzr 1.6)
1 change: 1 addition & 0 deletions spec/fixtures/bazaar-repo/.bzr/branch/last-revision
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4 [email protected]
1 change: 1 addition & 0 deletions spec/fixtures/bazaar-repo/.bzr/branch/tags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d12:my_other_tag53:[email protected]:my_tag53:[email protected]
1 change: 1 addition & 0 deletions spec/fixtures/bazaar-repo/.bzr/checkout/conflicts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BZR conflict list format 1
Binary file added spec/fixtures/bazaar-repo/.bzr/checkout/dirstate
Binary file not shown.
1 change: 1 addition & 0 deletions spec/fixtures/bazaar-repo/.bzr/checkout/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bazaar Working Tree Format 6 (bzr 1.14)
Empty file.
1 change: 1 addition & 0 deletions spec/fixtures/bazaar-repo/.bzr/repository/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bazaar repository format 2a (needs bzr 1.16 or later)
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
B+Tree Graph Index 2
node_ref_lists=1
key_elements=1
len=1
row_lengths=1
x��Q@0@�=E/@��h|H\��"A7����ܟp��*\<i���1�;�j�G 2�:��p�_�ۺ��V�E�L��I��'��
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
B+Tree Graph Index 2
node_ref_lists=0
key_elements=1
len=0
row_lengths=
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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а=w�w�qY�����"e�1�3\Y��̘ڥ�I�u�����rI�ڢ'
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
B+Tree Graph Index 2
node_ref_lists=0
key_elements=1
len=0
row_lengths=
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
B+Tree Graph Index 2
node_ref_lists=0
key_elements=1
len=0
row_lengths=
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
B+Tree Graph Index 2
node_ref_lists=0
key_elements=1
len=0
row_lengths=
Binary file not shown.
7 changes: 7 additions & 0 deletions spec/fixtures/bazaar-repo/.bzr/repository/pack-names
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
B+Tree Graph Index 2
node_ref_lists=0
key_elements=1
len=4
row_lengths=1
x�E�;�1 DQ�Y�����
X�ǖ�����3PE����x�����>�����u��űO�&�s]�,�CZpC�~�Lj��u�1�]GZ���ސ�A�G��k���:GL�C��6������I�t����އwuQ=ߥN�D�� ��1�
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions spec/fixtures/bazaar-repo/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fourth Commit
2 changes: 2 additions & 0 deletions spec/fixtures/mercurial-repo/.hg/cache/tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 df97b9ee89577f2da1925154472888b2b57e971e