Class: Git
- Inherits:
-
Object
- Object
- Git
- Defined in:
- lib/mark_version/git.rb
Class Method Summary collapse
- .ahead_of_branch_by(branch) ⇒ Object
- .ahead_of_release_by ⇒ Object
- .ahead_of_version?(branch) ⇒ Boolean
- .ahead_of_version_by(branch) ⇒ Object
- .branch ⇒ Object
- .closest_release_branch ⇒ Object
- .commit(version) ⇒ Object
- .commit_and_tag(version) ⇒ Object
- .current_ahead_by ⇒ Object
- .current_ahead_of_version? ⇒ Boolean
- .last_version_commit ⇒ Object
- .on_release_branch? ⇒ Boolean
- .push ⇒ Object
- .short_hash ⇒ Object
- .tag(version) ⇒ Object
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_by ⇒ Object
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
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 |
.branch ⇒ Object
2 3 4 |
# File 'lib/mark_version/git.rb', line 2 def self.branch `git rev-parse --abbrev-ref HEAD`.chomp end |
.closest_release_branch ⇒ Object
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_by ⇒ Object
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
14 15 16 |
# File 'lib/mark_version/git.rb', line 14 def self.current_ahead_of_version? ahead_of_version?('HEAD') end |
.last_version_commit ⇒ Object
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
44 45 46 |
# File 'lib/mark_version/git.rb', line 44 def self.on_release_branch? MarkVersionConfig.new.release_branches.include?(branch) end |
.push ⇒ Object
70 71 72 |
# File 'lib/mark_version/git.rb', line 70 def self.push `git push origin --tags` end |
.short_hash ⇒ Object
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 |