Class: GitBump
- Inherits:
-
Thor
- Object
- Thor
- GitBump
- Defined in:
- lib/git_bump.rb
Defined Under Namespace
Constant Summary collapse
- INITIAL =
<<-EOS Looks like this is your first release. Please add the version number to the work tree (e.g., in your Makefile), stage your changes, and run git bump again. If this isn't your first release, tag your most recent prior release so that git bump can find it: git tag -s v1.2.3 8675309 EOS
Class Method Summary collapse
Instance Method Summary collapse
- #log(*args) ⇒ Object
- #next(specifier = nil) ⇒ Object
- #redo ⇒ Object
- #release(request = nil) ⇒ Object
- #show(version = latest ? latest.version.to_s : nil) ⇒ Object
Class Method Details
.basename ⇒ Object
182 183 184 |
# File 'lib/git_bump.rb', line 182 def self.basename 'git bump' end |
.help(shell) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/git_bump.rb', line 267 def self.help(shell, *) super shell.say <<-EOS With no arguments, git bump defaults to creating a release with the least significant component of the version number incremented. For example, 1.2.3-rc4 becomes 1.2.3-rc5, while 6.7 becomes 6.8. To override, provide a version number argument, or one of the following keywords: major: bump the most significant component minor: bump the second most significant component point: bump the third most significant component EOS end |
.start ⇒ Object
17 18 19 20 |
# File 'lib/git_bump.rb', line 17 def self.start ARGV.unshift('release') if ARGV.first =~ /^v?\d/ || %w(major minor point).include?(ARGV.first) super end |
Instance Method Details
#log(*args) ⇒ Object
237 238 239 240 241 242 243 |
# File 'lib/git_bump.rb', line 237 def log(*args) if latest exec('git', 'log', "#{latest.sha1}..", *args) else exec('git', 'log', *args) end end |
#next(specifier = nil) ⇒ Object
263 264 265 |
# File 'lib/git_bump.rb', line 263 def next(specifier = nil) puts generate_version(specifier) end |
#redo ⇒ Object
225 226 227 228 229 230 231 232 233 234 |
# File 'lib/git_bump.rb', line 225 def redo unless %x{git diff}.empty? abort "Discard or stage your changes." end unless latest && latest.sha1 == %x{git rev-parse HEAD}.chomp abort "Can only amend the top-most commit." end system!('git', 'commit', '--amend', '--verbose', '--reset-author') tag!(latest.tag) end |
#release(request = nil) ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/git_bump.rb', line 189 def release(request=nil) version = generate_version(request) unless %x{git rev-parse --verify -q v#{version}}.empty? || [:force] abort "Tag already exists. If it hasn't been pushed yet, use --force to override." end initial_commit = %x{git rev-parse --verify -q HEAD}.empty? if !initial_commit && %x{git diff HEAD}.empty? abort INITIAL unless latest failure = "Couldn't patch. Update the version number in the work tree and try again." abort failure unless patch = patch(version, [:force]) IO.popen(['git', 'apply', '--unidiff-zero', '--index'], 'w') do |o| o.write patch end abort failure unless $?.success? hard = true elsif %x{git diff --cached}.empty? # TODO: what happens on initial with some unstaged changes? abort "Discard or stage your changes." end require 'tempfile' Tempfile.open('git-commit') do |f| f.puts [name, version].join(' ') f.puts f.write logs if latest f.flush system('git', 'commit', '--file', f.path, '--edit', * initial_commit ? [] : ['--verbose']) unless $?.success? system('git', 'reset', '-q', '--hard', 'HEAD') if hard abort end end tag!("v#{version}") end |
#show(version = latest ? latest.version.to_s : nil) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/git_bump.rb', line 247 def show(version = latest ? latest.version.to_s : nil) release = releases.detect do |r| r.version.to_s == version || r.tag == version end if release if [:version_only] puts release.version else exec('git', 'log', '-1', '--pretty=format:%B', release.sha1) end else exit 1 end end |