Skip to content

Commit

Permalink
Merge pull request #2 from gouketsu/patch-1
Browse files Browse the repository at this point in the history
fix an issue when we use alias in bazaar
  • Loading branch information
Da-wei committed Nov 4, 2014
2 parents ec0ff3a + 210d423 commit 1b348fb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
33 changes: 32 additions & 1 deletion lib/berkshelf/locations/bzr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def installed?
#
# @see BaseLocation#install
def install
if cached?
if cached? && valid?
Dir.chdir(cache_path) do
bzr %|pull|
end
Expand Down Expand Up @@ -146,6 +146,37 @@ def revid(path)
end
end

# Retrieve repository branch name or parent branch from a info output
#
# @return [string]
def retrieve_branch(output)
result = output.match(/repository branch: (.*)/)
return result.captures if result != nil
result = output.match(/parent branch: (.*)/)
return result.captures if result != nil
''
end

# Determine if a bazaar cached location is valid
# Needed when we use alias in Berksfile
#
# @return [Boolean]
def valid?
# Get information
stdout_cached=''
Dir.chdir(cache_path) do
stdout_cached = retrieve_branch(bzr %|info|)
end
stdout_new = retrieve_branch(bzr %|info #{uri}|)
# Check if alias has been moved to a new release
if stdout_cached != stdout_new then
FileUtils.rm_rf cache_path
false
else
true
end
end

# Determine if this bazaar repo has already been downloaded.
#
# @return [Boolean]
Expand Down
1 change: 1 addition & 0 deletions spec/unit/locations/bzr_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module Berkshelf
it 'pulls a new version' do
Dir.stub(:chdir).and_yield
subject.stub(:cached?).and_return(true)
subject.stub(:valid?).and_return(true)
expect(subject).to receive(:bzr).with('pull')
subject.install
end
Expand Down

0 comments on commit 1b348fb

Please sign in to comment.