Class: Promote::GitRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/promote/git_repo.rb

Defined Under Namespace

Classes: EmptyTag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope_path) ⇒ GitRepo

Returns a new instance of GitRepo.



3
4
5
# File 'lib/promote/git_repo.rb', line 3

def initialize(scope_path)
  @scope_path = scope_path
end

Instance Attribute Details

#scope_pathObject

Returns the value of attribute scope_path.



71
72
73
# File 'lib/promote/git_repo.rb', line 71

def scope_path
  @scope_path
end

Instance Method Details

#check_sync(source, dest) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/promote/git_repo.rb', line 51

def check_sync(source, dest)
  warnings = []
  refresh_index
  if git.status.changed.to_h.keys.include? source
    warnings << "File #{source} has uncommitted changes."
  end
  git.fetch
  git.diff('master','origin/master').entries.each do |f|
    if f.path == source || f.path == dest
      warnings << "File #{f.path} is not synced with origin/master."
    end
  end
  if warnings.count > 0
    puts '*** Git sync issues: Fix the following issues and try again:'
    warnings.each { |w| puts "* #{w}" }
    exit 1
  end
end

#commit(msg, push = false) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/promote/git_repo.rb', line 37

def commit(msg, push = false)
  git.add(scope_path)
  if !(git.status.changed.select{|s| scope_path.end_with?(s)}).keys.empty?
    git.commit(msg)
    git.push if push
  end
end

#current_tagObject



19
20
21
22
23
24
25
26
27
# File 'lib/promote/git_repo.rb', line 19

def current_tag
  if @current_tag.nil?
    @current_tag = git.tags.select { |t| t.name[/^[0-9\.]+/] }[-1]
    if @current_tag.nil?
      @current_tag = EmptyTag.new
    end
  end
  @current_tag
end

#gitObject



14
15
16
17
# File 'lib/promote/git_repo.rb', line 14

def git
  require 'git'
  @git ||= Git.open(git_root(scope_path))
end

#refresh_indexObject



45
46
47
48
49
# File 'lib/promote/git_repo.rb', line 45

def refresh_index
  git.diff("HEAD", scope_path).each do |diff|
    # we do this to refresh the index
  end
end

#sha1Object



29
30
31
32
33
34
35
# File 'lib/promote/git_repo.rb', line 29

def sha1
  if @sha1.nil?
    first_commit = log.first
    @sha1 = first_commit.nil? ? '' : first_commit.sha
  end
  @sha1
end

#version_numberObject



7
8
9
10
11
12
# File 'lib/promote/git_repo.rb', line 7

def version_number
  all_commit_count = log.size
  bump_commit_count = log.grep("CI:bumping").size
  commit_count = all_commit_count - bump_commit_count
  "#{current_tag.name}.#{commit_count}"
end