Sha256: a1d9d436b694826439118ca007489680907ab9191b28574a509a3de9388a98ae

Contents?: true

Size: 1.35 KB

Versions: 24

Compression:

Stored size: 1.35 KB

Contents

class KnifeChangelog
  class Git
    attr_accessor :tmp_prefix, :uri

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

    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

    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

    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

    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

    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
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
knife-changelog-2.0.0 lib/knife/changelog/git.rb
knife-changelog-1.7.0 lib/knife/changelog/git.rb
knife-changelog-1.6.0 lib/knife/changelog/git.rb
knife-changelog-1.5.0 lib/knife/changelog/git.rb
knife-changelog-1.4.2 lib/knife/changelog/git.rb
knife-changelog-1.4.1 lib/knife/changelog/git.rb
knife-changelog-1.4.0 lib/knife/changelog/git.rb
knife-changelog-1.3.0 lib/knife/changelog/git.rb
knife-changelog-1.2.5 lib/knife/changelog/git.rb
knife-changelog-1.2.4 lib/knife/changelog/git.rb
knife-changelog-1.2.3 lib/knife/changelog/git.rb
knife-changelog-1.2.2 lib/knife/changelog/git.rb
knife-changelog-1.2.1 lib/knife/changelog/git.rb
knife-changelog-1.2.0 lib/knife/changelog/git.rb
knife-changelog-1.1.0 lib/knife/changelog/git.rb
knife-changelog-1.0.10 lib/knife/changelog/git.rb
knife-changelog-1.0.9 lib/knife/changelog/git.rb
knife-changelog-1.0.8 lib/knife/changelog/git.rb
knife-changelog-1.0.7 lib/knife/changelog/git.rb
knife-changelog-1.0.6 lib/knife/changelog/git.rb