Module: Jets::Git::GitCli
Instance Method Summary collapse
- #git(args, on_error: :nil) ⇒ Object
- #git? ⇒ Boolean
-
#git_commits? ⇒ Boolean
Edge case: git init but no commits yet.
- #git_folder? ⇒ Boolean
- #git_installed? ⇒ Boolean
Instance Method Details
#git(args, on_error: :nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jets/git/git_cli.rb', line 20 def git(args, on_error: :nil) out = `git #{args}`.strip unless $?.success? case on_error when :raise raise Jets::Git::Error, "ERROR: git #{args} failed".color(:red) when :nil return end end out end |
#git? ⇒ Boolean
3 4 5 |
# File 'lib/jets/git/git_cli.rb', line 3 def git? git_folder? && git_installed? && git_commits? end |
#git_commits? ⇒ Boolean
Edge case: git init but no commits yet
16 17 18 |
# File 'lib/jets/git/git_cli.rb', line 16 def git_commits? system "git rev-parse HEAD >/dev/null 2>&1" end |
#git_folder? ⇒ Boolean
7 8 9 |
# File 'lib/jets/git/git_cli.rb', line 7 def git_folder? File.exist?(".git") end |
#git_installed? ⇒ Boolean
11 12 13 |
# File 'lib/jets/git/git_cli.rb', line 11 def git_installed? system "type git > /dev/null 2>&1" end |