Class: Git

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

Class Method Summary collapse

Class Method Details

.ahead_of_branch_by(branch) ⇒ Object



26
27
28
# File 'lib/mark_version/git.rb', line 26

def self.ahead_of_branch_by(branch)
  `git rev-list #{branch}..HEAD --count`.chomp
end

.ahead_of_release_byObject



22
23
24
# File 'lib/mark_version/git.rb', line 22

def self.ahead_of_release_by
  `git rev-list #{closest_release_branch}..HEAD --count`.chomp
end

.ahead_of_version?(branch) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/mark_version/git.rb', line 10

def self.ahead_of_version?(branch)
  self.ahead_of_version_by(branch).to_i > 0
end

.ahead_of_version_by(branch) ⇒ Object



6
7
8
# File 'lib/mark_version/git.rb', line 6

def self.ahead_of_version_by(branch)
  `git rev-list #{self.last_version_commit}..#{branch} --count`.chomp
end

.branchObject



2
3
4
# File 'lib/mark_version/git.rb', line 2

def self.branch
  `git rev-parse --abbrev-ref HEAD`.chomp
end

.closest_release_branchObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mark_version/git.rb', line 30

def self.closest_release_branch
  branch = nil
  distance = nil

  MarkVersionConfig.new.release_branches.each do |branch|
    if distance.nil? || ahead_of_branch_by(branch) < distance
      branch = branch
      distance = ahead_of_branch_by(branch)
    end
  end

  branch || 'master'
end

.commit(version) ⇒ Object



61
62
63
64
# File 'lib/mark_version/git.rb', line 61

def self.commit(version)
  `git add VERSION`
  `git commit -m "To version #{version}"`
end

.commit_and_tag(version) ⇒ Object



56
57
58
59
# File 'lib/mark_version/git.rb', line 56

def self.commit_and_tag(version)
  commit(version)
  tag(version)
end

.current_ahead_byObject



18
19
20
# File 'lib/mark_version/git.rb', line 18

def self.current_ahead_by
  ahead_of_version_by('HEAD')
end

.current_ahead_of_version?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/mark_version/git.rb', line 14

def self.current_ahead_of_version?
  ahead_of_version?('HEAD')
end

.last_version_commitObject



52
53
54
# File 'lib/mark_version/git.rb', line 52

def self.last_version_commit
  `git log --format="%h" VERSION | head -n 1`.chomp
end

.on_release_branch?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/mark_version/git.rb', line 44

def self.on_release_branch?
  MarkVersionConfig.new.release_branches.include?(branch)
end

.pushObject



70
71
72
# File 'lib/mark_version/git.rb', line 70

def self.push
  `git push origin --tags`
end

.short_hashObject



48
49
50
# File 'lib/mark_version/git.rb', line 48

def self.short_hash
  `git rev-parse --short HEAD`.chomp
end

.tag(version) ⇒ Object



66
67
68
# File 'lib/mark_version/git.rb', line 66

def self.tag(version)
  `git tag #{version} -a -m "Release version #{version}"`
end