tap: add methods to get git related information
These methods will be used in `brew --version`, `brew config` and `brew doctor` after core/formula separation. Closes Homebrew/homebrew#49796. Signed-off-by: Xu Cheng <xucheng@me.com>
This commit is contained in:
parent
a2d0d88bf1
commit
9f96e41b40
@ -83,7 +83,7 @@ class Tap
|
|||||||
# e.g. `https://github.com/user/homebrew-repo`
|
# e.g. `https://github.com/user/homebrew-repo`
|
||||||
def remote
|
def remote
|
||||||
@remote ||= if installed?
|
@remote ||= if installed?
|
||||||
if git?
|
if git? && Utils.git_available?
|
||||||
path.cd do
|
path.cd do
|
||||||
Utils.popen_read("git", "config", "--get", "remote.origin.url").chomp
|
Utils.popen_read("git", "config", "--get", "remote.origin.url").chomp
|
||||||
end
|
end
|
||||||
@ -98,6 +98,34 @@ class Tap
|
|||||||
(path/".git").exist?
|
(path/".git").exist?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# git HEAD for this {Tap}.
|
||||||
|
def git_head
|
||||||
|
raise TapUnavailableError, name unless installed?
|
||||||
|
return unless git? && Utils.git_available?
|
||||||
|
path.cd { Utils.popen_read("git", "rev-parse", "--verify", "-q", "HEAD").chuzzle }
|
||||||
|
end
|
||||||
|
|
||||||
|
# git HEAD in short format for this {Tap}.
|
||||||
|
def git_short_head
|
||||||
|
raise TapUnavailableError, name unless installed?
|
||||||
|
return unless git? && Utils.git_available?
|
||||||
|
path.cd { Utils.popen_read("git", "rev-parse", "--short=4", "--verify", "-q", "HEAD").chuzzle }
|
||||||
|
end
|
||||||
|
|
||||||
|
# time since git last commit for this {Tap}.
|
||||||
|
def git_last_commit
|
||||||
|
raise TapUnavailableError, name unless installed?
|
||||||
|
return unless git? && Utils.git_available?
|
||||||
|
path.cd { Utils.popen_read("git", "show", "-s", "--format=%cr", "HEAD").chuzzle }
|
||||||
|
end
|
||||||
|
|
||||||
|
# git last commit date for this {Tap}.
|
||||||
|
def git_last_commit_date
|
||||||
|
raise TapUnavailableError, name unless installed?
|
||||||
|
return unless git? && Utils.git_available?
|
||||||
|
path.cd { Utils.popen_read("git", "show", "-s", "--format=%cd", "--date=short", "HEAD").chuzzle }
|
||||||
|
end
|
||||||
|
|
||||||
# The issues URL of this {Tap}.
|
# The issues URL of this {Tap}.
|
||||||
# e.g. `https://github.com/user/homebrew-repo/issues`
|
# e.g. `https://github.com/user/homebrew-repo/issues`
|
||||||
def issues_url
|
def issues_url
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
require "testing_env"
|
require "testing_env"
|
||||||
|
|
||||||
class TapTest < Homebrew::TestCase
|
class TapTest < Homebrew::TestCase
|
||||||
|
include FileUtils
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo"
|
@path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo"
|
||||||
@path.mkpath
|
@path.mkpath
|
||||||
@ -16,7 +18,7 @@ class TapTest < Homebrew::TestCase
|
|||||||
EOS
|
EOS
|
||||||
@alias_file = @path/"Aliases/bar"
|
@alias_file = @path/"Aliases/bar"
|
||||||
@alias_file.parent.mkpath
|
@alias_file.parent.mkpath
|
||||||
FileUtils.ln_s @formula_file, @alias_file
|
ln_s @formula_file, @alias_file
|
||||||
(@path/"formula_renames.json").write <<-EOS.undent
|
(@path/"formula_renames.json").write <<-EOS.undent
|
||||||
{ "oldname": "foo" }
|
{ "oldname": "foo" }
|
||||||
EOS
|
EOS
|
||||||
@ -25,14 +27,21 @@ class TapTest < Homebrew::TestCase
|
|||||||
EOS
|
EOS
|
||||||
@cmd_file = @path/"cmd/brew-tap-cmd.rb"
|
@cmd_file = @path/"cmd/brew-tap-cmd.rb"
|
||||||
@cmd_file.parent.mkpath
|
@cmd_file.parent.mkpath
|
||||||
FileUtils.touch @cmd_file
|
touch @cmd_file
|
||||||
FileUtils.chmod 0755, @cmd_file
|
chmod 0755, @cmd_file
|
||||||
@manpage_file = @path/"man/man1/brew-tap-cmd.1"
|
@manpage_file = @path/"man/man1/brew-tap-cmd.1"
|
||||||
@manpage_file.parent.mkpath
|
@manpage_file.parent.mkpath
|
||||||
FileUtils.touch @manpage_file
|
touch @manpage_file
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_git_repo
|
def setup_git_repo
|
||||||
|
env = ENV.to_hash
|
||||||
|
%w[AUTHOR COMMITTER].each do |role|
|
||||||
|
ENV["GIT_#{role}_NAME"] = "brew tests"
|
||||||
|
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
||||||
|
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
||||||
|
end
|
||||||
|
|
||||||
@path.cd do
|
@path.cd do
|
||||||
shutup do
|
shutup do
|
||||||
system "git", "init"
|
system "git", "init"
|
||||||
@ -41,6 +50,8 @@ class TapTest < Homebrew::TestCase
|
|||||||
system "git", "commit", "-m", "init"
|
system "git", "commit", "-m", "init"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
|
ENV.replace(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@ -74,7 +85,7 @@ class TapTest < Homebrew::TestCase
|
|||||||
t = Tap.new("someone", "foo")
|
t = Tap.new("someone", "foo")
|
||||||
path = Tap::TAP_DIRECTORY/"someone/homebrew-foo"
|
path = Tap::TAP_DIRECTORY/"someone/homebrew-foo"
|
||||||
path.mkpath
|
path.mkpath
|
||||||
FileUtils.cd path do
|
cd path do
|
||||||
shutup { system "git", "init" }
|
shutup { system "git", "init" }
|
||||||
system "git", "remote", "add", "origin",
|
system "git", "remote", "add", "origin",
|
||||||
"https://github.com/someone/homebrew-foo"
|
"https://github.com/someone/homebrew-foo"
|
||||||
@ -123,6 +134,26 @@ class TapTest < Homebrew::TestCase
|
|||||||
refute_predicate version_tap, :private?
|
refute_predicate version_tap, :private?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_remote_not_git_repo
|
||||||
|
assert_nil @tap.remote
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_remote_git_not_available
|
||||||
|
setup_git_repo
|
||||||
|
Utils.stubs(:git_available?).returns(false)
|
||||||
|
assert_nil @tap.remote
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_git_variant
|
||||||
|
touch @path/"README"
|
||||||
|
setup_git_repo
|
||||||
|
|
||||||
|
assert_equal "e1893a6bd191ba895c71b652ff8376a6114c7fa7", @tap.git_head
|
||||||
|
assert_equal "e189", @tap.git_short_head
|
||||||
|
assert_match %r{years ago}, @tap.git_last_commit
|
||||||
|
assert_equal "2009-05-21", @tap.git_last_commit_date
|
||||||
|
end
|
||||||
|
|
||||||
def test_private_remote
|
def test_private_remote
|
||||||
skip "HOMEBREW_GITHUB_API_TOKEN is required" unless ENV["HOMEBREW_GITHUB_API_TOKEN"]
|
skip "HOMEBREW_GITHUB_API_TOKEN is required" unless ENV["HOMEBREW_GITHUB_API_TOKEN"]
|
||||||
assert_predicate @tap, :private?
|
assert_predicate @tap, :private?
|
||||||
@ -174,6 +205,8 @@ class TapTest < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
class CoreFormulaRepositoryTest < Homebrew::TestCase
|
class CoreFormulaRepositoryTest < Homebrew::TestCase
|
||||||
|
include FileUtils
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@repo = CoreFormulaRepository.new
|
@repo = CoreFormulaRepository.new
|
||||||
end
|
end
|
||||||
@ -204,7 +237,7 @@ class CoreFormulaRepositoryTest < Homebrew::TestCase
|
|||||||
EOS
|
EOS
|
||||||
@alias_file = @repo.alias_dir/"bar"
|
@alias_file = @repo.alias_dir/"bar"
|
||||||
@alias_file.parent.mkpath
|
@alias_file.parent.mkpath
|
||||||
FileUtils.ln_s @formula_file, @alias_file
|
ln_s @formula_file, @alias_file
|
||||||
|
|
||||||
assert_equal [@formula_file], @repo.formula_files
|
assert_equal [@formula_file], @repo.formula_files
|
||||||
assert_equal ["foo"], @repo.formula_names
|
assert_equal ["foo"], @repo.formula_names
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user