Class: HomebrewAutomation::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/homebrew_automation/git.rb

Overview

Git effects

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#clone!(url, dir: nil) ⇒ NilClass

Just git clone the given URL

Parameters:

  • url (String)

    git-friendly URL; could be filesystem path

  • dir (String) (defaults to: nil)

    optionally specify target dir name

Returns:

  • (NilClass)


35
36
37
38
39
40
41
# 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) ⇒ NilClass

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

Parameters:

  • msg (String)

    Git commit message

Returns:

  • (NilClass)


73
74
75
# File 'lib/homebrew_automation/git.rb', line 73

def commit_am!(msg)
  raise_unless 'git', 'commit', '--allow-empty', '-am', msg
end

#config!NilClass

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.

Returns:

  • (NilClass)


21
22
23
24
25
26
27
28
# 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!NilClass

Just git push

Returns:

  • (NilClass)


80
81
82
# File 'lib/homebrew_automation/git.rb', line 80

def push!
  raise_unless 'git', 'push'
end

#with_clone!(url, dir, keep_dir: false) {|dir| ... } ⇒ NilClass

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

Parameters:

  • url (String)
  • dir (String)
  • keep_dir (Boolean) (defaults to: false)

Yield Parameters:

  • dir (String)

    name of freshly cloned dir

Yield Returns:

  • (a)

    anything

Returns:

  • (NilClass)

See Also:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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