Class: Jets::Git::Local
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_branch ⇒ Object
24
25
26
|
# File 'lib/jets/git/local.rb', line 24
def git_branch
git "rev-parse --abbrev-ref HEAD"
end
|
#git_current_branch ⇒ Object
69
70
71
|
# File 'lib/jets/git/local.rb', line 69
def git_current_branch
`rev-parse --abbrev-ref HEAD`.strip
end
|
#git_default_branch ⇒ Object
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
37
38
39
|
# File 'lib/jets/git/local.rb', line 37
def git_dirty?
!git("status --porcelain").empty?
end
|
#git_message ⇒ Object
20
21
22
|
# File 'lib/jets/git/local.rb', line 20
def git_message
git "log -1 --pretty=%B"
end
|
#git_remote ⇒ Object
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
`git remote 2>&1`
return unless $?.success?
`git remote`.strip end
|
#git_sha ⇒ Object
28
29
30
|
# File 'lib/jets/git/local.rb', line 28
def git_sha
git "rev-parse HEAD"
end
|
#git_url ⇒ Object
32
33
34
35
|
# File 'lib/jets/git/local.rb', line 32
def git_url
git "config --get remote.#{git_remote}.url"
end
|
#git_version ⇒ Object
41
42
43
|
# File 'lib/jets/git/local.rb', line 41
def git_version
git "--version", on_error: :raise
end
|
#info ⇒ Object
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
|