Class: ChefCLI::Policyfile::ComparisonBase::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-cli/policyfile/comparison_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ref, policyfile_lock_relpath) ⇒ Git

Returns a new instance of Git.



57
58
59
60
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 57

def initialize(ref, policyfile_lock_relpath)
  @ref = ref
  @policyfile_lock_relpath = policyfile_lock_relpath
end

Instance Attribute Details

#policyfile_lock_relpathObject (readonly)

Returns the value of attribute policyfile_lock_relpath.



55
56
57
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 55

def policyfile_lock_relpath
  @policyfile_lock_relpath
end

#refObject (readonly)

Returns the value of attribute ref.



54
55
56
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 54

def ref
  @ref
end

Instance Method Details

#git_cmdObject



76
77
78
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 76

def git_cmd
  @git_cmd ||= Mixlib::ShellOut.new(git_cmd_string)
end

#git_cmd_stringObject



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 80

def git_cmd_string
  # Git is a little picky about how we specify the paths, but it looks
  # like we don't need to worry about the relative path to the root of
  # the repo if we give git a leading dot:
  #
  #    git show 6644e6cb2ade90b8aff2ebb44728958fbc939ebf:zero.rb
  #    fatal: Path 'etc/zero.rb' exists, but not 'zero.rb'.
  #    Did you mean '6644e6cb2ade90b8aff2ebb44728958fbc939ebf:etc/zero.rb' aka '6644e6cb2ade90b8aff2ebb44728958fbc939ebf:./zero.rb'?
  #    git show 6644e6cb2ade90b8aff2ebb44728958fbc939ebf:./zero.rb
  #    (works)
  "git show #{ref}:./#{policyfile_lock_relpath}"
end

#lockObject



66
67
68
69
70
71
72
73
74
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 66

def lock
  git_cmd.run_command
  git_cmd.error!
  FFI_Yajl::Parser.parse(git_cmd.stdout)
rescue Mixlib::ShellOut::ShellCommandFailed
  raise GitError, "Git command `#{git_cmd_string}` failed with message: #{git_cmd.stderr.chomp}"
rescue FFI_Yajl::ParseError => e
  raise MalformedLockfile, "Invalid JSON in lockfile at git ref '#{ref}' at path '#{policyfile_lock_relpath}':\n  #{e.message}"
end

#nameObject



62
63
64
# File 'lib/chef-cli/policyfile/comparison_base.rb', line 62

def name
  "git:#{ref}"
end