Remove use of bash
This commit is contained in:
parent
00f74902d4
commit
028b8b408d
@ -81,7 +81,8 @@ module Homebrew
|
|||||||
|
|
||||||
Look through repository history to find the most recent version of <formula> and
|
Look through repository history to find the most recent version of <formula> and
|
||||||
create a copy in <tap>`/Formula/`<formula>`@`<version>`.rb`. If the tap is not
|
create a copy in <tap>`/Formula/`<formula>`@`<version>`.rb`. If the tap is not
|
||||||
installed yet, attempt to install/clone the tap before continuing.
|
installed yet, attempt to install/clone the tap before continuing. To extract
|
||||||
|
a <formula> from a tap that is not homebrew/core use <user>/<repo>/<formula>.
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
flag "--version=",
|
flag "--version=",
|
||||||
@ -112,7 +113,12 @@ module Homebrew
|
|||||||
destination_tap.install unless destination_tap.installed?
|
destination_tap.install unless destination_tap.installed?
|
||||||
|
|
||||||
repo = source_tap.path
|
repo = source_tap.path
|
||||||
pattern = source_tap.core_tap? ? repo/"Formula/#{name}.rb" : repo/"{,**/}#{name}.rb"
|
pattern = if source_tap.core_tap?
|
||||||
|
[repo/"Formula/#{name}.rb"]
|
||||||
|
else
|
||||||
|
# A formula can technically live in the root directory of a tap or in any of its subdirectories
|
||||||
|
[repo/"#{name}.rb", repo/"**/#{name}.rb"]
|
||||||
|
end
|
||||||
|
|
||||||
if args.version
|
if args.version
|
||||||
ohai "Searching repository history"
|
ohai "Searching repository history"
|
||||||
@ -138,6 +144,7 @@ module Homebrew
|
|||||||
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
|
||||||
|
# Search in the root directory of <repo> as well as recursively in all of its subdirectories
|
||||||
files = Dir[repo/"{,**/}"].map do |dir|
|
files = Dir[repo/"{,**/}"].map do |dir|
|
||||||
Pathname.glob(["#{dir}/#{name}.rb"]).find(&:file?)
|
Pathname.glob(["#{dir}/#{name}.rb"]).find(&:file?)
|
||||||
end.compact
|
end.compact
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
describe "brew extract", :integration_test do
|
describe "brew extract", :integration_test do
|
||||||
it "retrieves the specified version of formula from core tap, defaulting to most recent" do
|
it "retrieves the specified version of formula, defaulting to most recent" 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)
|
||||||
@ -29,69 +29,4 @@ describe "brew extract", :integration_test do
|
|||||||
|
|
||||||
expect(Formulary.factory(path/"Formula/testball@0.1.rb").version).to be == "0.1"
|
expect(Formulary.factory(path/"Formula/testball@0.1.rb").version).to be == "0.1"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "retrieves the specified version of formula from a tap other than core, defaulting to most recent" do
|
|
||||||
destination = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo"
|
|
||||||
(destination/"Formula").mkpath
|
|
||||||
destination_tap = Tap.from_path(destination)
|
|
||||||
|
|
||||||
source = Tap::TAP_DIRECTORY/"homebrew/homebrew-bar"
|
|
||||||
source.mkpath
|
|
||||||
source_tap = Tap.from_path(source)
|
|
||||||
|
|
||||||
tarball = if OS.linux?
|
|
||||||
TEST_FIXTURE_DIR/"tarballs/testball-0.1-linux.tbz"
|
|
||||||
else
|
|
||||||
TEST_FIXTURE_DIR/"tarballs/testball-0.1.tbz"
|
|
||||||
end
|
|
||||||
|
|
||||||
content = <<~RUBY
|
|
||||||
desc "Some test"
|
|
||||||
homepage "https://brew.sh/testball"
|
|
||||||
url "file://#{tarball}"
|
|
||||||
sha256 "#{tarball.sha256}"
|
|
||||||
|
|
||||||
option "with-foo", "Build with foo"
|
|
||||||
|
|
||||||
def install
|
|
||||||
(prefix/"foo"/"test").write("test") if build.with? "foo"
|
|
||||||
prefix.install Dir["*"]
|
|
||||||
(buildpath/"test.c").write \
|
|
||||||
"#include <stdio.h>\\nint main(){return printf(\\"test\\");}"
|
|
||||||
bin.mkpath
|
|
||||||
system ENV.cc, "test.c", "-o", bin/"test"
|
|
||||||
end
|
|
||||||
RUBY
|
|
||||||
|
|
||||||
formula_file = source_tap.path/"testball.rb"
|
|
||||||
formula_file.write <<~RUBY
|
|
||||||
class Testball < Formula
|
|
||||||
#{content}
|
|
||||||
end
|
|
||||||
RUBY
|
|
||||||
|
|
||||||
source_tap.path.cd do
|
|
||||||
system "git", "init"
|
|
||||||
system "git", "add", "--all"
|
|
||||||
system "git", "commit", "-m", "testball 0.1"
|
|
||||||
contents = File.read(formula_file)
|
|
||||||
contents.gsub!("testball-0.1", "testball-0.2")
|
|
||||||
File.write(formula_file, contents)
|
|
||||||
system "git", "add", "--all"
|
|
||||||
system "git", "commit", "-m", "testball 0.2"
|
|
||||||
end
|
|
||||||
expect { brew "extract", "homebrew/bar/testball", destination_tap.name }
|
|
||||||
.to be_a_success
|
|
||||||
|
|
||||||
expect(destination/"Formula/testball@0.2.rb").to exist
|
|
||||||
|
|
||||||
expect(Formulary.factory(destination/"Formula/testball@0.2.rb").version).to be == "0.2"
|
|
||||||
|
|
||||||
expect { brew "extract", "homebrew/bar/testball", destination_tap.name, "--version=0.1" }
|
|
||||||
.to be_a_success
|
|
||||||
|
|
||||||
expect(destination/"Formula/testball@0.1.rb").to exist
|
|
||||||
|
|
||||||
expect(Formulary.factory(destination/"Formula/testball@0.1.rb").version).to be == "0.1"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -4,7 +4,11 @@ module Git
|
|||||||
module_function
|
module_function
|
||||||
|
|
||||||
def last_revision_commit_of_file(repo, file, before_commit: nil)
|
def last_revision_commit_of_file(repo, file, before_commit: nil)
|
||||||
args = [before_commit.nil? ? "--skip=1" : before_commit.split("..").first]
|
args = if before_commit.nil?
|
||||||
|
["--skip=1"]
|
||||||
|
else
|
||||||
|
[before_commit.split("..").first]
|
||||||
|
end
|
||||||
|
|
||||||
out, = Open3.capture3(
|
out, = Open3.capture3(
|
||||||
HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo,
|
HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo,
|
||||||
@ -14,17 +18,26 @@ module Git
|
|||||||
out.chomp
|
out.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_revision_commit_of_files(repo, file, before_commit: nil)
|
def last_revision_commit_of_files(repo, files, before_commit: nil)
|
||||||
args = [before_commit.nil? ? "--skip=1" : before_commit.split("..").first]
|
args = if before_commit.nil?
|
||||||
|
["--skip=1"]
|
||||||
|
else
|
||||||
|
[before_commit.split("..").first]
|
||||||
|
end
|
||||||
|
|
||||||
cmd = [
|
# git log output format:
|
||||||
HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo,
|
# <commit_hash>
|
||||||
"log", "--format=%h", "--abbrev=7", "--max-count=1", "--name-only",
|
# <file_path1>
|
||||||
*args, "--", file
|
# <file_path2>
|
||||||
]
|
# ...
|
||||||
out, = Open3.capture3("/bin/bash", "-c", cmd.join(" "))
|
# return [<commit_hash>, [file_path1, file_path2, ...]]
|
||||||
rev, *files = out.chomp.split(/\n/).reject(&:empty?)
|
out, = Open3.capture3(
|
||||||
[rev, files]
|
HOMEBREW_SHIMS_PATH/"scm/git", "-C", repo, "log",
|
||||||
|
"--pretty=format:%h", "--abbrev=7", "--max-count=1",
|
||||||
|
"--diff-filter=d", "--name-only", *args, "--", *files
|
||||||
|
)
|
||||||
|
rev, *paths = out.chomp.split(/\n/).reject(&:empty?)
|
||||||
|
[rev, paths]
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_revision_of_file(repo, file, before_commit: nil)
|
def last_revision_of_file(repo, file, before_commit: nil)
|
||||||
|
|||||||
@ -785,7 +785,8 @@ Homebrew repository for editing if no *`formula`* is provided.
|
|||||||
|
|
||||||
Look through repository history to find the most recent version of *`formula`* and
|
Look through repository history to find the most recent version of *`formula`* and
|
||||||
create a copy in *`tap`*`/Formula/`*`formula`*`@`*`version`*`.rb`. If the tap is not
|
create a copy in *`tap`*`/Formula/`*`formula`*`@`*`version`*`.rb`. If the tap is not
|
||||||
installed yet, attempt to install/clone the tap before continuing.
|
installed yet, attempt to install/clone the tap before continuing. To extract a
|
||||||
|
*`formula`* from a tap that is not homebrew/core use *`user`*/*`repo`*/*`formula`*.
|
||||||
|
|
||||||
* `--version`:
|
* `--version`:
|
||||||
Extract the provided *`version`* of *`formula`* instead of the most recent.
|
Extract the provided *`version`* of *`formula`* instead of the most recent.
|
||||||
|
|||||||
@ -985,7 +985,7 @@ Generate the new formula in the provided tap, specified as \fIuser\fR\fB/\fR\fIr
|
|||||||
Open a formula in the editor set by \fBEDITOR\fR or \fBHOMEBREW_EDITOR\fR, or open the Homebrew repository for editing if no \fIformula\fR is provided\.
|
Open a formula in the editor set by \fBEDITOR\fR or \fBHOMEBREW_EDITOR\fR, or open the Homebrew repository for editing if no \fIformula\fR is provided\.
|
||||||
.
|
.
|
||||||
.SS "\fBextract\fR [\fIoptions\fR] \fIformula\fR \fItap\fR"
|
.SS "\fBextract\fR [\fIoptions\fR] \fIformula\fR \fItap\fR"
|
||||||
Look through repository history to find the most recent version of \fIformula\fR and create a copy in \fItap\fR\fB/Formula/\fR\fIformula\fR\fB@\fR\fIversion\fR\fB\.rb\fR\. If the tap is not installed yet, attempt to install/clone the tap before continuing\.
|
Look through repository history to find the most recent version of \fIformula\fR and create a copy in \fItap\fR\fB/Formula/\fR\fIformula\fR\fB@\fR\fIversion\fR\fB\.rb\fR\. If the tap is not installed yet, attempt to install/clone the tap before continuing\. To extract a \fIformula\fR from a tap that is not homebrew/core use \fIuser\fR/\fIrepo\fR/\fIformula\fR\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-version\fR
|
\fB\-\-version\fR
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user