Merge pull request #6800 from figroc/extract-semver-aware
extract: semver aware
This commit is contained in:
commit
4a7ea6dbc4
@ -125,24 +125,34 @@ module Homebrew
|
|||||||
if args.version
|
if args.version
|
||||||
ohai "Searching repository history"
|
ohai "Searching repository history"
|
||||||
version = args.version
|
version = args.version
|
||||||
rev = "HEAD"
|
version_segments = Gem::Version.new(version).segments if Gem::Version.correct?(version)
|
||||||
|
rev = nil
|
||||||
test_formula = nil
|
test_formula = nil
|
||||||
result = ""
|
result = ""
|
||||||
loop do
|
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?
|
odie "Could not find #{name}! The formula or version may not have existed." if rev.nil?
|
||||||
|
|
||||||
file = repo/path
|
file = repo/path
|
||||||
result = Git.last_revision_of_file(repo, file, before_commit: rev)
|
result = Git.last_revision_of_file(repo, file, before_commit: rev)
|
||||||
if result.empty?
|
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
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
test_formula = formula_at_revision(repo, name, file, rev)
|
test_formula = formula_at_revision(repo, name, file, rev)
|
||||||
break if test_formula.nil? || test_formula.version == version
|
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
|
end
|
||||||
odie "Could not find #{name}! The formula or version may not have existed." if test_formula.nil?
|
odie "Could not find #{name}! The formula or version may not have existed." if test_formula.nil?
|
||||||
else
|
else
|
||||||
@ -181,7 +191,7 @@ module Homebrew
|
|||||||
brew extract --force --version=#{version} #{name} #{destination_tap.name}
|
brew extract --force --version=#{version} #{name} #{destination_tap.name}
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
odebug "Overwriting existing formula at #{path}" if ARGV.debug?
|
odebug "Overwriting existing formula at #{path}"
|
||||||
path.delete
|
path.delete
|
||||||
end
|
end
|
||||||
ohai "Writing formula for #{name} from revision #{rev} to #{path}"
|
ohai "Writing formula for #{name} from revision #{rev} to #{path}"
|
||||||
|
|||||||
@ -7,7 +7,7 @@ describe "Homebrew.extract_args" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "brew extract", :integration_test do
|
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 = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo"
|
||||||
(path/"Formula").mkpath
|
(path/"Formula").mkpath
|
||||||
target = Tap.from_path(path)
|
target = Tap.from_path(path)
|
||||||
@ -23,12 +23,27 @@ describe "brew extract", :integration_test do
|
|||||||
system "git", "add", "--all"
|
system "git", "add", "--all"
|
||||||
system "git", "commit", "-m", "testball 0.2"
|
system "git", "commit", "-m", "testball 0.2"
|
||||||
end
|
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
|
.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
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user