Class: Jets::Git::Local

Inherits:
Base
  • Object
show all
Includes:
GitCli
Defined in:
lib/jets/git/local.rb

Instance Method Summary collapse

Methods included from GitCli

#git, #git?, #git_folder?, #git_installed?

Methods inherited from Base

#base, #params, #user

Instance Method Details

#git_branchObject



24
25
26
# File 'lib/jets/git/local.rb', line 24

def git_branch
  git "rev-parse --abbrev-ref HEAD"
end

#git_current_branchObject



69
70
71
# File 'lib/jets/git/local.rb', line 69

def git_current_branch
  `rev-parse --abbrev-ref HEAD`.strip
end

#git_default_branchObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/jets/git/local.rb', line 55

def git_default_branch
  default = ENV["JETS_GIT_DEFAULT_BRANCH"] || "master"
  out = `git remote show origin 2>&1`.strip
  return default unless $?.success?

  lines = out.split("\n")
  lines.each do |line|
    if line.include?("HEAD")
      return line.split(" ").last
    end
  end
  default
end

#git_dirty?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/jets/git/local.rb', line 37

def git_dirty?
  !git("status --porcelain").empty?
end

#git_messageObject



20
21
22
# File 'lib/jets/git/local.rb', line 20

def git_message
  git "log -1 --pretty=%B"
end

#git_remoteObject

discover git remote name. in case it’s not origin



46
47
48
49
50
51
52
# File 'lib/jets/git/local.rb', line 46

def git_remote
  # 2>&1 to suppress error message
  #   "fatal: not a git repository (or any parent up to mount point /path)\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).\n"
  `git remote 2>&1`
  return unless $?.success?
  `git remote`.strip # IE: origin or blank string
end

#git_shaObject



28
29
30
# File 'lib/jets/git/local.rb', line 28

def git_sha
  git "rev-parse HEAD"
end

#git_urlObject



32
33
34
35
# File 'lib/jets/git/local.rb', line 32

def git_url
  # IE: git "config --get remote.origin.url"
  git "config --get remote.#{git_remote}.url"
end

#git_versionObject



41
42
43
# File 'lib/jets/git/local.rb', line 41

def git_version
  git "--version", on_error: :raise
end

#infoObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jets/git/local.rb', line 5

def info
  return {} unless git? && git_branch
  info = {
    git_system: "local",
    git_branch: git_branch,
    git_sha: git_sha,
    git_dirty: git_dirty?,
    git_message: git_message,
    git_version: git_version,
    git_default_branch: git_default_branch
  }
  info[:git_url] = git_url if git_url
  info
end