Class: Versioneer::Git

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

Constant Summary collapse

H =
Helpers

Instance Attribute Summary

Attributes inherited from Repo

#bump_segment, #environment, #prereleases, #release_pattern, #starting_release

Instance Method Summary collapse

Methods inherited from Repo

bump, segment_to_i, #to_s, #version

Constructor Details

#initialize(file_within_repo, options = nil) ⇒ Git

Returns a new instance of Git.



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

def initialize(file_within_repo, options=nil)
  super
  unless Dir.exist?(File.join(file_within_repo, '.git'))
    unless H.lines? `git ls-files #{file_within_repo} --error-unmatch #{H.cl_no_stderr}`
      raise InvalidRepoError, "Not inside a Git repo. (#{file_within_repo})"
    end
  end
end

Instance Method Details

#commits_since_releaseObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/versioneer/git.rb', line 24

def commits_since_release
  offset = 0
  unless (ref = release_ref)
    unless (ref = first_ref)
      return 0
    end
    offset = 1
  end
  H.num_of_lines(`git log #{ref}...HEAD --pretty=oneline #{H.cl_no_stderr}`) + offset
end

#filesystem_dirty?Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/versioneer/git.rb', line 35

def filesystem_dirty?
  system 'git diff-index --quiet HEAD --'
  $?.exitstatus != 0
end

#releaseObject



16
17
18
19
20
21
22
# File 'lib/versioneer/git.rb', line 16

def release
  if (ref = release_ref)
    Gem::Version.new(ref.match(release_pattern)[1])
  else
    super
  end
end