Merge pull request #4191 from reitermarkus/unnecessary-cd

Get rid of unnecessary `cd`s.
This commit is contained in:
Markus Reiter 2018-05-21 22:37:16 +02:00 committed by GitHub
commit 77b5a11907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 33 deletions

View File

@ -8,56 +8,36 @@ module GitRepositoryExtension
def git_origin
return unless git? && Utils.git_available?
cd do
Utils.popen_read("git", "config", "--get", "remote.origin.url").chuzzle
end
Utils.popen_read("git", "config", "--get", "remote.origin.url", chdir: self).chuzzle
end
def git_origin=(origin)
return unless git? && Utils.git_available?
cd do
safe_system "git", "remote", "set-url", "origin", origin
end
safe_system "git", "remote", "set-url", "origin", origin, chdir: self
end
def git_head
return unless git? && Utils.git_available?
cd do
Utils.popen_read("git", "rev-parse", "--verify", "-q", "HEAD").chuzzle
end
Utils.popen_read("git", "rev-parse", "--verify", "-q", "HEAD", chdir: self).chuzzle
end
def git_short_head
return unless git? && Utils.git_available?
cd do
Utils.popen_read(
"git", "rev-parse", "--short=4", "--verify", "-q", "HEAD"
).chuzzle
end
Utils.popen_read("git", "rev-parse", "--short=4", "--verify", "-q", "HEAD", chdir: self).chuzzle
end
def git_last_commit
return unless git? && Utils.git_available?
cd do
Utils.popen_read("git", "show", "-s", "--format=%cr", "HEAD").chuzzle
end
Utils.popen_read("git", "show", "-s", "--format=%cr", "HEAD", chdir: self).chuzzle
end
def git_branch
return unless git? && Utils.git_available?
cd do
Utils.popen_read(
"git", "rev-parse", "--abbrev-ref", "HEAD"
).chuzzle
end
Utils.popen_read("git", "rev-parse", "--abbrev-ref", "HEAD", chdir: self).chuzzle
end
def git_last_commit_date
return unless git? && Utils.git_available?
cd do
Utils.popen_read(
"git", "show", "-s", "--format=%cd", "--date=short", "HEAD"
).chuzzle
end
Utils.popen_read("git", "show", "-s", "--format=%cd", "--date=short", "HEAD", chdir: self).chuzzle
end
end

View File

@ -177,12 +177,12 @@ end
module Homebrew
module_function
def _system(cmd, *args)
def _system(cmd, *args, **options)
pid = fork do
yield if block_given?
args.collect!(&:to_s)
begin
exec(cmd, *args)
exec(cmd, *args, **options)
rescue
nil
end
@ -192,9 +192,9 @@ module Homebrew
$CHILD_STATUS.success?
end
def system(cmd, *args)
def system(cmd, *args, **options)
puts "#{cmd} #{args * " "}" if ARGV.verbose?
_system(cmd, *args)
_system(cmd, *args, **options)
end
def install_gem!(name, version = nil)
@ -294,8 +294,8 @@ def run_as_not_developer
end
# Kernel.system but with exceptions
def safe_system(cmd, *args)
Homebrew.system(cmd, *args) || raise(ErrorDuringExecution.new(cmd, args))
def safe_system(cmd, *args, **options)
Homebrew.system(cmd, *args, **options) || raise(ErrorDuringExecution.new(cmd, args))
end
# prints no output