Class: KnifeChangelog::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/knife/changelog/git.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tmp_prefix, uri) ⇒ Git

Returns a new instance of Git.



5
6
7
8
# File 'lib/knife/changelog/git.rb', line 5

def initialize(tmp_prefix, uri)
  @tmp_prefix = tmp_prefix
  @uri = uri
end

Instance Attribute Details

#tmp_prefixObject

Returns the value of attribute tmp_prefix.



3
4
5
# File 'lib/knife/changelog/git.rb', line 3

def tmp_prefix
  @tmp_prefix
end

#uriObject

Returns the value of attribute uri.



3
4
5
# File 'lib/knife/changelog/git.rb', line 3

def uri
  @uri
end

Instance Method Details

#diff(filename, current_rev, rev_parse) ⇒ Object



27
28
29
30
31
# File 'lib/knife/changelog/git.rb', line 27

def diff(filename, current_rev, rev_parse)
  diff = Mixlib::ShellOut.new("git diff #{current_rev}..#{rev_parse} --word-diff -- #{filename}", cwd: @clone_dir)
  diff.run_command
  diff.stdout.lines
end

#files(rev_parse) ⇒ Object



20
21
22
23
24
25
# File 'lib/knife/changelog/git.rb', line 20

def files(rev_parse)
  ls_tree = Mixlib::ShellOut.new("git ls-tree -r #{rev_parse}", cwd: @clone_dir)
  ls_tree.run_command
  ls_tree.error!
  ls_tree.stdout.lines.map(&:strip)
end

#log(current_rev, rev_parse) ⇒ Object



33
34
35
36
37
# File 'lib/knife/changelog/git.rb', line 33

def log(current_rev, rev_parse)
  log = Mixlib::ShellOut.new("git log --no-merges --abbrev-commit --pretty=oneline #{current_rev}..#{rev_parse}", cwd: @clone_dir)
  log.run_command
  log.stdout.lines
end

#revision_exists?(revision) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/knife/changelog/git.rb', line 39

def revision_exists?(revision)
  Chef::Log.debug "Testing existence of #{revision}"
  revlist = Mixlib::ShellOut.new("git rev-list --quiet #{revision}", cwd: @clone_dir)
  revlist.run_command
  !revlist.error?
end

#shallow_cloneObject



10
11
12
13
14
15
16
17
18
# File 'lib/knife/changelog/git.rb', line 10

def shallow_clone
  Chef::Log.debug "Cloning #{uri} in #{tmp_prefix}"
  dir = Dir.mktmpdir(tmp_prefix)
  clone = Mixlib::ShellOut.new("git clone --bare #{uri} bare-clone", cwd: dir)
  clone.run_command
  clone.error!
  @clone_dir = ::File.join(dir, 'bare-clone')
  @clone_dir
end