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

Added :tag and :branch options to mercurial downloader #18

Merged
merged 8 commits into from
Apr 14, 2014
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Master

* Added support for `:tag` option in mercurial sources. [Esteban Bouza](https://github.com/estebanbouza) [#16](https://github.com/CocoaPods/cocoapods-downloader/issues/16)
* Added support for `:branch` option in mercurial sources. [Esteban Bouza](https://github.com/estebanbouza) [#17](https://github.com/CocoaPods/cocoapods-downloader/issues/17)

## 0.4.1

* add shellescape for some path arguments in git.rb
Expand Down
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The downloader class supports the following option keys:

- git: commit, tag, branch, submodules
- svn: revision, tag, folder, externals
- hg: revision
- hg: revision, tag, branch
- http: type, flatten
- bzr: revision, tag

Expand Down
15 changes: 13 additions & 2 deletions lib/cocoapods-downloader/mercurial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module Downloader
class Mercurial < Base

def self.options
[:revision]
[:revision, :tag, :branch]
end

def options_specific?
!options[:revision].nil?
!options[:revision].nil? || !options[:tag].nil?
end

def checkout_options
Expand All @@ -26,6 +26,10 @@ def checkout_options
def download!
if options[:revision]
download_revision!
elsif options[:tag]
download_tag!
elsif options[:branch]
download_branch!
else
download_head!
end
Expand All @@ -38,7 +42,14 @@ def download_head!
def download_revision!
hg! %|clone "#{url}" --rev '#{options[:revision]}' #{@target_path.shellescape}|
end

def download_tag!
hg! %|clone "#{url}" --updaterev '#{options[:tag]}' #{@target_path.shellescape}|
end

def download_branch!
hg! %|clone "#{url}" --updaterev '#{options[:branch]}' #{@target_path.shellescape}|
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/mercurial-repo/.hg/branch
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feature/feature-branch
4 changes: 4 additions & 0 deletions spec/fixtures/mercurial-repo/.hg/cache/branch2-served
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
61118fa8988c2b2eae826f48abd1e3340dae0c6b 6
df97b9ee89577f2da1925154472888b2b57e971e o default
19118fbb9cfe74d008dc95b4ea5a8ad66e77c2d6 o develop
61118fa8988c2b2eae826f48abd1e3340dae0c6b o feature/feature-branch
4 changes: 3 additions & 1 deletion spec/fixtures/mercurial-repo/.hg/cache/branchheads
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
df97b9ee89577f2da1925154472888b2b57e971e 1
61118fa8988c2b2eae826f48abd1e3340dae0c6b 6
df97b9ee89577f2da1925154472888b2b57e971e default
19118fbb9cfe74d008dc95b4ea5a8ad66e77c2d6 develop
61118fa8988c2b2eae826f48abd1e3340dae0c6b feature/feature-branch
3 changes: 2 additions & 1 deletion spec/fixtures/mercurial-repo/.hg/cache/tags
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
1 df97b9ee89577f2da1925154472888b2b57e971e
6 61118fa8988c2b2eae826f48abd1e3340dae0c6b bb28287c416162ff25dc683f54ea1b473ff9a535

3c8b8d211b03c7e686049a8558e4c297104291eb 1.0.0
Binary file modified spec/fixtures/mercurial-repo/.hg/dirstate
Binary file not shown.
2 changes: 1 addition & 1 deletion spec/fixtures/mercurial-repo/.hg/last-message.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Second commit
Added fourth commit
Binary file modified spec/fixtures/mercurial-repo/.hg/store/00changelog.i
Binary file not shown.
Binary file modified spec/fixtures/mercurial-repo/.hg/store/00manifest.i
Binary file not shown.
Binary file modified spec/fixtures/mercurial-repo/.hg/store/data/_r_e_a_d_m_e.i
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions spec/fixtures/mercurial-repo/.hg/store/fncache
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
data/.hgtags.i
data/README.i
1 change: 1 addition & 0 deletions spec/fixtures/mercurial-repo/.hg/store/phaseroots
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 38d4e4277e34a2d7026f1dcccfe2c5b63ea24a05
Binary file modified spec/fixtures/mercurial-repo/.hg/store/undo
Binary file not shown.
1 change: 1 addition & 0 deletions spec/fixtures/mercurial-repo/.hg/store/undo.phaseroots
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 38d4e4277e34a2d7026f1dcccfe2c5b63ea24a05
2 changes: 1 addition & 1 deletion spec/fixtures/mercurial-repo/.hg/undo.branch
Original file line number Diff line number Diff line change
@@ -1 +1 @@
default
feature/feature-branch
2 changes: 1 addition & 1 deletion spec/fixtures/mercurial-repo/.hg/undo.desc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1
6
commit
Binary file modified spec/fixtures/mercurial-repo/.hg/undo.dirstate
Binary file not shown.
1 change: 1 addition & 0 deletions spec/fixtures/mercurial-repo/.hgtags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3c8b8d211b03c7e686049a8558e4c297104291eb 1.0.0
2 changes: 1 addition & 1 deletion spec/fixtures/mercurial-repo/README
Original file line number Diff line number Diff line change
@@ -1 +1 @@
second commit
fourth commit
38 changes: 38 additions & 0 deletions spec/mercurial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ module Downloader
downloader.download
tmp_folder_with_quotes('README').read.strip.should == 'second commit'
end

it "checks out a specific tag" do
options = { :hg => fixture('mercurial-repo'), :tag => '1.0.0' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes('README').read.strip.should == 'third commit'
end

it "checks out the branch head revision" do
options = { :hg => fixture('mercurial-repo'), :branch => 'feature/feature-branch' }
downloader = Downloader.for_target(tmp_folder_with_quotes, options)
downloader.download
tmp_folder_with_quotes('README').read.strip.should == 'fourth commit'
end

end

it "returns the checked out revision" do
Expand All @@ -51,13 +66,36 @@ module Downloader
it "returns whether the provided options are specific" do
Downloader.for_target('path', :hg => 'url').options_specific?.should.be.false
Downloader.for_target('path', :hg => 'url', :revision => '').options_specific?.should.be.true
Downloader.for_target('path', :hg => 'url', :tag => '').options_specific?.should.be.true
Downloader.for_target('path', :hg => 'url', :branch => '').options_specific?.should.be.false
end

it "raises if it fails to download" do
options = { :hg => 'missing-repo', :revision => '46198bb3af96' }
downloader = Downloader.for_target(tmp_folder, options)
lambda { downloader.download }.should.raise DownloaderError
end

it "checks out a specific tag" do
options = { :hg => fixture('mercurial-repo'), :tag => '1.0.0'}
downloader = Downloader.for_target(tmp_folder, options)
downloader.download
downloader.checkout_options.should == {
:hg => fixture('mercurial-repo'),
:revision => '3c8b8d211b03c7e686049a8558e4c297104291eb'
}
end

it "checks out a specific branch head" do
options = { :hg => fixture('mercurial-repo'), :branch => 'feature/feature-branch'}
downloader = Downloader.for_target(tmp_folder, options)
downloader.download
downloader.checkout_options.should == {
:hg => fixture('mercurial-repo'),
:revision => '61118fa8988c2b2eae826f48abd1e3340dae0c6b'
}
end

end
end
end