Module: SugarJar::Git
- Defined in:
- lib/sugarjar/git.rb
Class Method Summary collapse
- .in_repo? ⇒ Boolean
- .repo_root ⇒ Object
- .run(color: true) ⇒ Object
- .run_nofail(*args, color: true) ⇒ Object
Class Method Details
.in_repo? ⇒ Boolean
20 21 22 23 |
# File 'lib/sugarjar/git.rb', line 20 def self.in_repo? s = run_nofail('rev-parse', '--is-inside-work-tree') !s.error? && s.stdout.strip == 'true' end |
.repo_root ⇒ Object
25 26 27 |
# File 'lib/sugarjar/git.rb', line 25 def self.repo_root run('rev-parse', '--show-toplevel').stdout.strip end |
.run(color: true) ⇒ Object
14 15 16 17 18 |
# File 'lib/sugarjar/git.rb', line 14 def self.run(*, color: true) s = run_nofail(*, :color => color) s.error! s end |
.run_nofail(*args, color: true) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/sugarjar/git.rb', line 5 def self.run_nofail(*args, color: true) if %w{diff log grep branch}.include?(args[0]) && args.none? { |x| x.include?('color') } args << (color ? '--color' : '--no-color') end SugarJar::Log.trace("Running: git #{args.join(' ')}") Mixlib::ShellOut.new([SugarJar::Util.which('git')] + args).run_command end |