Module: Jets::Git::GitCli

Included in:
Local, User
Defined in:
lib/jets/git/git_cli.rb

Instance Method Summary collapse

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

Returns:

  • (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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


7
8
9
# File 'lib/jets/git/git_cli.rb', line 7

def git_folder?
  File.exist?(".git")
end

#git_installed?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/jets/git/git_cli.rb', line 11

def git_installed?
  system "type git > /dev/null 2>&1"
end