class HomebrewAutomation::Git

Git effects

Public Instance Methods

clone!(url, dir: nil) click to toggle source

Just +git clone+ the given URL

@param url [String] git-friendly URL; could be filesystem path @param dir [String] optionally specify target dir name @return [NilClass]

# File lib/homebrew_automation/git.rb, line 35
def clone!(url, dir: nil)
  if dir
    raise_unless 'git', 'clone', url, dir
  else
    raise_unless 'git', 'clone', url
  end
end
commit_am!(msg) click to toggle source

+git commit –allow-empty -am “$msg”+

@param msg [String] Git commit message @return [NilClass]

# File lib/homebrew_automation/git.rb, line 73
def commit_am!(msg)
  raise_unless 'git', 'commit', '--allow-empty', '-am', msg
end
config!() click to toggle source

Set Git user's name and email

Reads environment variables:

  • TRAVIS_GIT_USER_NAME

  • TRAVIS_GIT_USER_EMAIL

If either env var is not set, do nothing.

@return [NilClass]

# File lib/homebrew_automation/git.rb, line 21
def config!
  name = ENV['TRAVIS_GIT_USER_NAME']
  email = ENV['TRAVIS_GIT_USER_EMAIL']
  if name && email
    raise_unless 'git', 'config', '--global', 'user.name', name
    raise_unless 'git', 'config', '--global', 'user.email', email
  end
end
push!() click to toggle source

Just +git push+

@return [NilClass]

# File lib/homebrew_automation/git.rb, line 80
def push!
  raise_unless 'git', 'push'
end
with_clone!(url, dir, keep_dir: false, &block) click to toggle source

Like {#clone!} , but allows you to do something inside the newly cloned directory, pushd-style.

@see clone! @param url [String] @param dir [String] @param keep_dir [Boolean] @yieldparam dir [String] name of freshly cloned dir @yieldreturn [a] anything @return [NilClass]

# File lib/homebrew_automation/git.rb, line 53
def with_clone!(url, dir, keep_dir: false, &block)
  begin
    clone! url, dir: dir
    if block
      Dir.chdir dir do
        block.call(File.realpath '.')
      end
    else
      puts "Strange, you're calling Git#with_clone! without a block."
    end
    nil
  ensure
    FileUtils.remove_dir(dir) unless keep_dir
  end
end

Private Instance Methods

raise_unless(*args) click to toggle source
# File lib/homebrew_automation/git.rb, line 86
def raise_unless(*args)
  begin
    result = system(*args)
    unless result
      raise Error, args.join(' ')
    end
    result
  end
end