Skip to content
Snippets Groups Projects
Unverified Commit 4a7ea6db authored by Mike McQuaid's avatar Mike McQuaid Committed by GitHub
Browse files

Merge pull request #6800 from figroc/extract-semver-aware

extract: semver aware
parents 6decac58 3c09ab0d
No related branches found
No related tags found
No related merge requests found
......@@ -125,24 +125,34 @@ module Homebrew
if args.version
ohai "Searching repository history"
version = args.version
rev = "HEAD"
version_segments = Gem::Version.new(version).segments if Gem::Version.correct?(version)
rev = nil
test_formula = nil
result = ""
loop do
rev, (path,) = Git.last_revision_commit_of_files(repo, pattern, before_commit: "#{rev}~1")
rev = rev.nil? ? "HEAD" : "#{rev}~1"
rev, (path,) = Git.last_revision_commit_of_files(repo, pattern, before_commit: rev)
odie "Could not find #{name}! The formula or version may not have existed." if rev.nil?
file = repo/path
result = Git.last_revision_of_file(repo, file, before_commit: rev)
if result.empty?
odebug "Skipping revision #{rev} - file is empty at this revision" if ARGV.debug?
odebug "Skipping revision #{rev} - file is empty at this revision"
next
end
test_formula = formula_at_revision(repo, name, file, rev)
break if test_formula.nil? || test_formula.version == version
odebug "Trying #{test_formula.version} from revision #{rev} against desired #{version}" if ARGV.debug?
if version_segments && Gem::Version.correct?(test_formula.version)
test_formula_version_segments = Gem::Version.new(test_formula.version).segments
if version_segments.length < test_formula_version_segments.length
odebug "Apply semantic versioning with #{test_formual_version_segments}"
break if version_segments == test_formula_version_segments.first(version_segments.length)
end
end
odebug "Trying #{test_formula.version} from revision #{rev} against desired #{version}"
end
odie "Could not find #{name}! The formula or version may not have existed." if test_formula.nil?
else
......@@ -181,7 +191,7 @@ module Homebrew
brew extract --force --version=#{version} #{name} #{destination_tap.name}
EOS
end
odebug "Overwriting existing formula at #{path}" if ARGV.debug?
odebug "Overwriting existing formula at #{path}"
path.delete
end
ohai "Writing formula for #{name} from revision #{rev} to #{path}"
......
......@@ -7,7 +7,7 @@ describe "Homebrew.extract_args" do
end
describe "brew extract", :integration_test do
it "retrieves the specified version of formula, defaulting to most recent" do
let!(:target) do
path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo"
(path/"Formula").mkpath
target = Tap.from_path(path)
......@@ -23,12 +23,27 @@ describe "brew extract", :integration_test do
system "git", "add", "--all"
system "git", "commit", "-m", "testball 0.2"
end
{ name: target.name, path: path }
end
expect { brew "extract", "testball", target.name, "--version=0.1" }
it "retrieves the most recent version of formula" do
expect { brew "extract", "testball", target[:name] }
.to be_a_success
expect(target[:path]/"Formula/testball@0.2.rb").to exist
expect(Formulary.factory(target[:path]/"Formula/testball@0.2.rb").version).to be == "0.2"
end
expect(path/"Formula/testball@0.1.rb").to exist
it "retrieves the specified version of formula" do
expect { brew "extract", "testball", target[:name], "--version=0.1" }
.to be_a_success
expect(target[:path]/"Formula/testball@0.1.rb").to exist
expect(Formulary.factory(target[:path]/"Formula/testball@0.1.rb").version).to be == "0.1"
end
expect(Formulary.factory(path/"Formula/testball@0.1.rb").version).to be == "0.1"
it "retrieves the compatible version of formula" do
expect { brew "extract", "testball", target[:name], "--version=0", "--debug" }
.to be_a_success
expect(target[:path]/"Formula/testball@0.rb").to exist
expect(Formulary.factory(target[:path]/"Formula/testball@0.rb").version).to be == "0.2"
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment