Class: Jets::Git::Local

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

Instance Method Summary collapse

Methods included from GitCli

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

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_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

#paramsObject



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

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