Class: Overview::Git

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

Class Method Summary collapse

Class Method Details

.branchObject



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

def self.branch
  CI.branch || `git rev-parse --abbrev-ref HEAD`.strip
end

.clean_tag(tag = self.tag) ⇒ Object



24
25
26
# File 'lib/appversion/git.rb', line 24

def self.clean_tag(tag=self.tag)
  tag.strip.sub('v','').split(/[\.,-]/).select { |e| e.is_number?}.first(3).join('.')
end

.commit_countObject



27
28
29
# File 'lib/appversion/git.rb', line 27

def self.commit_count
  `git rev-list --count HEAD`
end

.commit_count_since_tag(tag) ⇒ Object



30
31
32
# File 'lib/appversion/git.rb', line 30

def self.commit_count_since_tag(tag)
  `git rev-list --count ${tag}.. 2>/dev/null`
end

.installed?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/appversion/git.rb', line 33

def self.installed?
  system 'git --version >>/dev/null 2>&1'
end

.remoteObject



7
8
9
10
11
12
13
14
# File 'lib/appversion/git.rb', line 7

def self.remote
  begin
    `git remote -v show`.lines.first.strip.match(/github\.com[\/|:](.+)\.git/)[1]
  rescue
    $stderr.puts 'Unable to retrieve slug from >> git remote -v show'
    exit 1
  end
end

.repoObject



15
16
17
# File 'lib/appversion/git.rb', line 15

def self.repo
  CI.repo || remote
end

.tagObject



21
22
23
# File 'lib/appversion/git.rb', line 21

def self.tag
  (`git describe --tags --match 'v*' --abbrev=0 2>/dev/null` || 'HEAD').strip
end