Merge pull request #4191 from reitermarkus/unnecessary-cd
Get rid of unnecessary `cd`s.
This commit is contained in:
		
						commit
						77b5a11907
					
				@ -8,56 +8,36 @@ module GitRepositoryExtension
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  def git_origin
 | 
					  def git_origin
 | 
				
			||||||
    return unless git? && Utils.git_available?
 | 
					    return unless git? && Utils.git_available?
 | 
				
			||||||
    cd do
 | 
					    Utils.popen_read("git", "config", "--get", "remote.origin.url", chdir: self).chuzzle
 | 
				
			||||||
      Utils.popen_read("git", "config", "--get", "remote.origin.url").chuzzle
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def git_origin=(origin)
 | 
					  def git_origin=(origin)
 | 
				
			||||||
    return unless git? && Utils.git_available?
 | 
					    return unless git? && Utils.git_available?
 | 
				
			||||||
    cd do
 | 
					    safe_system "git", "remote", "set-url", "origin", origin, chdir: self
 | 
				
			||||||
      safe_system "git", "remote", "set-url", "origin", origin
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def git_head
 | 
					  def git_head
 | 
				
			||||||
    return unless git? && Utils.git_available?
 | 
					    return unless git? && Utils.git_available?
 | 
				
			||||||
    cd do
 | 
					    Utils.popen_read("git", "rev-parse", "--verify", "-q", "HEAD", chdir: self).chuzzle
 | 
				
			||||||
      Utils.popen_read("git", "rev-parse", "--verify", "-q", "HEAD").chuzzle
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def git_short_head
 | 
					  def git_short_head
 | 
				
			||||||
    return unless git? && Utils.git_available?
 | 
					    return unless git? && Utils.git_available?
 | 
				
			||||||
    cd do
 | 
					    Utils.popen_read("git", "rev-parse", "--short=4", "--verify", "-q", "HEAD", chdir: self).chuzzle
 | 
				
			||||||
      Utils.popen_read(
 | 
					 | 
				
			||||||
        "git", "rev-parse", "--short=4", "--verify", "-q", "HEAD"
 | 
					 | 
				
			||||||
      ).chuzzle
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def git_last_commit
 | 
					  def git_last_commit
 | 
				
			||||||
    return unless git? && Utils.git_available?
 | 
					    return unless git? && Utils.git_available?
 | 
				
			||||||
    cd do
 | 
					    Utils.popen_read("git", "show", "-s", "--format=%cr", "HEAD", chdir: self).chuzzle
 | 
				
			||||||
      Utils.popen_read("git", "show", "-s", "--format=%cr", "HEAD").chuzzle
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def git_branch
 | 
					  def git_branch
 | 
				
			||||||
    return unless git? && Utils.git_available?
 | 
					    return unless git? && Utils.git_available?
 | 
				
			||||||
    cd do
 | 
					    Utils.popen_read("git", "rev-parse", "--abbrev-ref", "HEAD", chdir: self).chuzzle
 | 
				
			||||||
      Utils.popen_read(
 | 
					 | 
				
			||||||
        "git", "rev-parse", "--abbrev-ref", "HEAD"
 | 
					 | 
				
			||||||
      ).chuzzle
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def git_last_commit_date
 | 
					  def git_last_commit_date
 | 
				
			||||||
    return unless git? && Utils.git_available?
 | 
					    return unless git? && Utils.git_available?
 | 
				
			||||||
    cd do
 | 
					    Utils.popen_read("git", "show", "-s", "--format=%cd", "--date=short", "HEAD", chdir: self).chuzzle
 | 
				
			||||||
      Utils.popen_read(
 | 
					 | 
				
			||||||
        "git", "show", "-s", "--format=%cd", "--date=short", "HEAD"
 | 
					 | 
				
			||||||
      ).chuzzle
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -177,12 +177,12 @@ end
 | 
				
			|||||||
module Homebrew
 | 
					module Homebrew
 | 
				
			||||||
  module_function
 | 
					  module_function
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def _system(cmd, *args)
 | 
					  def _system(cmd, *args, **options)
 | 
				
			||||||
    pid = fork do
 | 
					    pid = fork do
 | 
				
			||||||
      yield if block_given?
 | 
					      yield if block_given?
 | 
				
			||||||
      args.collect!(&:to_s)
 | 
					      args.collect!(&:to_s)
 | 
				
			||||||
      begin
 | 
					      begin
 | 
				
			||||||
        exec(cmd, *args)
 | 
					        exec(cmd, *args, **options)
 | 
				
			||||||
      rescue
 | 
					      rescue
 | 
				
			||||||
        nil
 | 
					        nil
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
@ -192,9 +192,9 @@ module Homebrew
 | 
				
			|||||||
    $CHILD_STATUS.success?
 | 
					    $CHILD_STATUS.success?
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def system(cmd, *args)
 | 
					  def system(cmd, *args, **options)
 | 
				
			||||||
    puts "#{cmd} #{args * " "}" if ARGV.verbose?
 | 
					    puts "#{cmd} #{args * " "}" if ARGV.verbose?
 | 
				
			||||||
    _system(cmd, *args)
 | 
					    _system(cmd, *args, **options)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def install_gem!(name, version = nil)
 | 
					  def install_gem!(name, version = nil)
 | 
				
			||||||
@ -294,8 +294,8 @@ def run_as_not_developer
 | 
				
			|||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Kernel.system but with exceptions
 | 
					# Kernel.system but with exceptions
 | 
				
			||||||
def safe_system(cmd, *args)
 | 
					def safe_system(cmd, *args, **options)
 | 
				
			||||||
  Homebrew.system(cmd, *args) || raise(ErrorDuringExecution.new(cmd, args))
 | 
					  Homebrew.system(cmd, *args, **options) || raise(ErrorDuringExecution.new(cmd, args))
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# prints no output
 | 
					# prints no output
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user