Module: Git::Commands
- Included in:
- ReleaseNotes, Tagger, Wiki
- Defined in:
- lib/git/commands.rb
Instance Method Summary collapse
- #assert_is_git_repo ⇒ Object
-
#get_branch ⇒ Object
figure out what branch the pwd’s repo is on.
-
#get_tags ⇒ Object
Find all version tags.
- #is_git_repo? ⇒ Boolean
- #next_version(options = {}) ⇒ Object
-
#valid_version_regexp ⇒ Object
e.g.
Instance Method Details
#assert_is_git_repo ⇒ Object
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_branch ⇒ Object
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_tags ⇒ Object
Find all version tags
24 25 26 27 |
# File 'lib/git/commands.rb', line 24 def 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
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(={}) latest_tag = .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 [:major] major.succ! minor, point = '0', '0' elsif [:minor] minor.succ! point = '0' elsif [:point] point.succ! else warn "unable to increment version number." end 'v' + [major, minor, point].join('.') end |
#valid_version_regexp ⇒ Object
e.g. v1.4.3
19 20 21 |
# File 'lib/git/commands.rb', line 19 def valid_version_regexp /^v\d+\.\d+\.\d+/ end |