Class: ChefCLI::CookbookProfiler::Git
- Inherits:
-
Object
- Object
- ChefCLI::CookbookProfiler::Git
show all
- Includes:
- Helpers
- Defined in:
- lib/chef-cli/cookbook_profiler/git.rb
Constant Summary
collapse
- @@git_memo =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Helpers
#err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_expand_path, #omnibus_install?, #omnibus_root, #package_home, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix
Constructor Details
#initialize(cookbook_path) ⇒ Git
Returns a new instance of Git.
34
35
36
37
38
39
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 34
def initialize(cookbook_path)
@cookbook_path = cookbook_path
@repo_path = nil
@unborn_branch = nil
@unborn_branch_ref = nil
end
|
Instance Attribute Details
#cookbook_path ⇒ Object
Returns the value of attribute cookbook_path.
28
29
30
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 28
def cookbook_path
@cookbook_path
end
|
Class Method Details
.uncache ⇒ Object
30
31
32
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 30
def self.uncache
@@git_memo = {}
end
|
Instance Method Details
#clean? ⇒ Boolean
70
71
72
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 70
def clean?
git!("diff-files --quiet", returns: [0, 1]).exitstatus == 0
end
|
#current_branch ⇒ Object
108
109
110
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 108
def current_branch
@current_branch ||= detect_current_branch
end
|
#have_remote? ⇒ Boolean
104
105
106
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 104
def have_remote?
!remote_name.empty? && remote_name != "."
end
|
#profile_data ⇒ Hash
Returns Hashed used for pinning cookbook versions within a Policyfile.lock.
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 42
def profile_data
{
"scm" => "git",
"remote" => remote,
"revision" => revision,
"working_tree_clean" => clean?,
"published" => !unpublished_commits?,
"synchronized_remote_branches" => synchronized_remotes,
}
end
|
#remote ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 91
def remote
@remote_url ||=
if have_remote?
git!("config --get remote.#{remote_name}.url").stdout.strip
else
nil
end
end
|
#remote_name ⇒ Object
100
101
102
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 100
def remote_name
@remote_name ||= git!("config --get branch.#{current_branch}.remote", returns: [0, 1]).stdout.strip
end
|
#revision ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 57
def revision
git!("rev-parse HEAD").stdout.strip
rescue Mixlib::ShellOut::ShellCommandFailed => e
if unborn_branch_ref
nil
else
raise e
end
end
|
#synchronized_remotes ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 78
def synchronized_remotes
@synchronized_remotes ||= git!("branch -r --contains #{revision}").stdout.lines.map(&:strip)
rescue Mixlib::ShellOut::ShellCommandFailed => e
if unborn_branch_ref
[]
else
raise e
end
end
|
#unpublished_commits? ⇒ Boolean
74
75
76
|
# File 'lib/chef-cli/cookbook_profiler/git.rb', line 74
def unpublished_commits?
synchronized_remotes.empty?
end
|