Skip to content

Instantly share code, notes, and snippets.

@dpmcnevin
Last active May 25, 2016 15:27
Show Gist options
  • Save dpmcnevin/a6c331fd44a075420da7c80b292a04d0 to your computer and use it in GitHub Desktop.
Save dpmcnevin/a6c331fd44a075420da7c80b292a04d0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'git'
require 'logger'
g = Git.open(Dir.pwd)
if ARGV.include?("-h") || ARGV.include?("--help")
puts <<-EOF
USAGE: git bump [options]
-h Print out help
-v Verbose output
--major Bump major version
--minor Bump minor version
--dry Don't create a new tag, just show what it would be
EOF
exit(0)
end
verbose = ARGV.include?("-v") || ARGV.include?("--verbose")
separator = ARGV.include?("--google") || ARGV.include?("-g") || g.config("core.gaeversion").eql?("true") ? "-" : "."
current_version = `git describe`.strip
@major, @minor, @patch = current_version.split(/[\.-]/)
@major ||= 0; @minor ||= 0; @patch ||= 0
if ARGV.include?("--major");
@major = @major.to_i.next; @minor = 0; @patch = 0
elsif ARGV.include?("--minor")
@minor = @minor.to_i.next; @patch = 0
else
@patch = @patch.to_i.next
end
new_version = [@major, @minor, @patch].join(separator)
puts "CURRENT VERSION: #{current_version}" if verbose
puts "NEW VERSION: #{new_version}"
unless ARGV.include?("--dry")
_command = "git tag -m '#{new_version}' #{new_version}"
puts "--> #{_command}" if verbose
system(_command)
_command = "git push --tags"
puts "--> #{_command}" if verbose
system(_command)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment