Class: ChefDK::CookbookProfiler::Git
- Inherits:
-
Object
- Object
- ChefDK::CookbookProfiler::Git
show all
- Includes:
- Helpers
- Defined in:
- lib/chef-dk/cookbook_profiler/git.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#chefdk_home, #err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix
Constructor Details
#initialize(cookbook_path) ⇒ Git
Returns a new instance of Git.
28
29
30
31
32
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 28
def initialize(cookbook_path)
@cookbook_path = cookbook_path
@unborn_branch = nil
@unborn_branch_ref = nil
end
|
Instance Attribute Details
#cookbook_path ⇒ Object
Returns the value of attribute cookbook_path.
26
27
28
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 26
def cookbook_path
@cookbook_path
end
|
Instance Method Details
#clean? ⇒ Boolean
63
64
65
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 63
def clean?
git!("diff-files --quiet", returns: [0, 1]).exitstatus == 0
end
|
#current_branch ⇒ Object
101
102
103
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 101
def current_branch
@current_branch ||= detect_current_branch
end
|
#have_remote? ⇒ Boolean
97
98
99
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 97
def have_remote?
!remote_name.empty? && remote_name != "."
end
|
#profile_data ⇒ Hash
Returns Hashed used for pinning cookbook versions within a Policfile.lock.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 35
def profile_data
{
"scm" => "git",
"remote" => remote,
"revision" => revision,
"working_tree_clean" => clean?,
"published" => !unpublished_commits?,
"synchronized_remote_branches" => synchronized_remotes,
}
end
|
#remote ⇒ Object
84
85
86
87
88
89
90
91
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 84
def remote
@remote_url ||=
if have_remote?
git!("config --get remote.#{remote_name}.url").stdout.strip
else
nil
end
end
|
#remote_name ⇒ Object
93
94
95
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 93
def remote_name
@remote_name ||= git!("config --get branch.#{current_branch}.remote", returns: [0, 1]).stdout.strip
end
|
#revision ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 50
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
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 71
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
67
68
69
|
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 67
def unpublished_commits?
synchronized_remotes.empty?
end
|