Sha256: d409a3f7712fe9f54bcf7ff3ac0b135745bd7a043930c42af49cc1266ee19d80

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

require 'fileutils'

module Stove
  module Git
    def git_init(path = Dir.pwd)
      cmd = [
        'cd "' + path + '"',
        'git init .',
        'git add --all',
        'git commit --message "Initial commit"',
        'git remote add origin file://' + fake_git_remote,
        'git push --quiet --force origin master',
      ].join(' && ')

      %x|#{cmd}|
    end

    def fake_git_remote
      path = File.expand_path(File.join(tmp_path, 'remote.git'))
      return path if File.exists?(path)

      FileUtils.mkdir_p(path)
      cmd = [
        'cd "' + path + '"',
        'git init .',
        'git config receive.denyCurrentBranch ignore',
        'git config receive.denyNonFastforwards true',
        'git config core.sharedrepository 1',
      ].join(' && ')

      %x|#{cmd}|

      path
    end

    def git_shas(path)
      %x|cd "#{path}" && git log --oneline|.split("\n").map { |line| line.split(/\s+/, 2).first.strip } rescue []
    end

    def git_commits(path)
      %x|cd "#{path}" && git log --oneline|.split("\n").map { |line| line.split(/\s+/, 2).last.strip } rescue []
    end

    def git_tags(path)
      %x|cd "#{path}" && git tag --list|.split("\n").map(&:strip) rescue []
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stove-2.0.0 features/support/stove/git.rb
stove-2.0.0.beta.2 features/support/stove/git.rb
stove-2.0.0.beta.1 features/support/stove/git.rb