Module: Git::Commands

Included in:
ReleaseNotes, Tagger, Wiki
Defined in:
lib/git/commands.rb

Instance Method Summary collapse

Instance Method Details

#assert_is_git_repoObject



4
5
6
# File 'lib/git/commands.rb', line 4

def assert_is_git_repo
  error "Not a git repository" unless is_git_repo?
end

#get_branchObject

figure out what branch the pwd’s repo is on



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

def get_branch
  match = Regexp.new("^# On branch (.*)").match(`git status`)
  match && match[1]
end

#get_tagsObject

Find all version tags



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

def get_tags
  version_regexp = valid_version_regexp
  %x{git tag}.split.grep(version_regexp).sort_by{|v| v.split('.').map{|nbr| nbr[/\d+/].to_i}}.map{|tag| tag.strip}
end

#is_git_repo?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/git/commands.rb', line 8

def is_git_repo?
  File.directory?('.git')
end

#next_version(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/git/commands.rb', line 29

def next_version(options={})
  latest_tag = get_tags.last
  return 'v0.0.1' unless latest_tag

  unless latest_tag.match valid_version_regexp
    warn "invalid version number"
    return latest_tag
  end

  major, minor, point = latest_tag.split('.')
  major = major[1..-1]
  if options[:major]
    major.succ!
    minor, point = '0', '0'
  elsif options[:minor]
    minor.succ!
    point = '0'
  elsif options[:point]
    point.succ!
  else
    warn "unable to increment version number."
  end

  'v' + [major, minor, point].join('.')
end

#valid_version_regexpObject

e.g. v1.4.3



19
20
21
# File 'lib/git/commands.rb', line 19

def valid_version_regexp
  /^v\d+\.\d+\.\d+/
end