Class: ChefDK::CookbookProfiler::Git

Inherits:
Object
  • Object
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

#err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #omnibus_root, #stderr, #stdout, #system_command

Constructor Details

#initialize(cookbook_path) ⇒ Git

Returns a new instance of Git.



28
29
30
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 28

def initialize(cookbook_path)
  @cookbook_path = cookbook_path
end

Instance Attribute Details

#cookbook_pathObject (readonly)

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

Returns:

  • (Boolean)


51
52
53
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 51

def clean?
  git!("diff-files --quiet", returns: [0,1]).exitstatus == 0
end

#current_branchObject



80
81
82
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 80

def current_branch
  @current_branch ||= git!('rev-parse --abbrev-ref HEAD').stdout.strip
end

#have_remote?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 76

def have_remote?
  !remote_name.empty?
end

#profile_dataObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 32

def profile_data
  {
    "scm" => "git",
    # To get this info, you need to do something like:
    # figure out branch or assume 'master'
    # git config --get branch.master.remote
    # git config --get remote.opscode.url
    "remote" => remote,
    "revision" => revision,
    "working_tree_clean" => clean?,
    "published" => !unpublished_commits?,
    "synchronized_remote_branches" => synchronized_remotes
  }
end

#remoteObject



63
64
65
66
67
68
69
70
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 63

def remote
  @remote_url ||=
    if have_remote?
      git!("config --get remote.#{remote_name}.url").stdout.strip
    else
      nil
    end
end

#remote_nameObject



72
73
74
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 72

def remote_name
  @remote_name ||= git!("config --get branch.#{current_branch}.remote", returns: [0,1]).stdout.strip
end

#revisionObject



47
48
49
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 47

def revision
  git!("rev-parse HEAD").stdout.strip
end

#synchronized_remotesObject



59
60
61
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 59

def synchronized_remotes
  @synchronized_remotes ||= git!("branch -r --contains #{revision}").stdout.lines.map(&:strip)
end

#unpublished_commits?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/chef-dk/cookbook_profiler/git.rb', line 55

def unpublished_commits?
  synchronized_remotes.empty?
end