Class: HomebrewAutomation::Git
- Inherits:
-
Object
- Object
- HomebrewAutomation::Git
- Defined in:
- lib/homebrew_automation/git.rb
Overview
Git effects
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#clone!(url, dir: nil) ⇒ NilClass
Just git clone the given URL.
-
#commit_am!(msg) ⇒ NilClass
git commit –allow-empty -am “$msg”.
-
#config! ⇒ NilClass
Set Git user’s name and email.
-
#push! ⇒ NilClass
Just git push.
-
#with_clone!(url, dir, keep_dir: false) {|dir| ... } ⇒ a
Like #clone! , but allows you to do something inside the newly cloned directory, pushd-style.
Instance Method Details
#clone!(url, dir: nil) ⇒ NilClass
Just git clone the given URL
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”
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.
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
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| ... } ⇒ a
Like #clone! , but allows you to do something inside the newly cloned directory, pushd-style.
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 |