Advertisement
Guest User

Untitled

a guest
May 25th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'git'
  4. require 'logger'
  5.  
  6. g = Git.open(Dir.pwd)
  7.  
  8. if ARGV.include?("-h") || ARGV.include?("--help")
  9. puts <<-EOF
  10. USAGE: git bump [options]
  11.  
  12. -h Print out help
  13. -v Verbose output
  14. --major Bump major version
  15. --minor Bump minor version
  16. --dry Don't create a new tag, just show what it would be
  17. EOF
  18. exit(0)
  19. end
  20.  
  21. verbose = ARGV.include?("-v") || ARGV.include?("--verbose")
  22. separator = ARGV.include?("--google") || ARGV.include?("-g") || g.config("core.gaeversion").eql?("true") ? "-" : "."
  23.  
  24. current_version = `git describe`.strip
  25.  
  26. @major, @minor, @patch = current_version.split(/[\.-]/)
  27.  
  28. @major ||= 0; @minor ||= 0; @patch ||= 0
  29.  
  30. if ARGV.include?("--major");
  31. @major = @major.to_i.next; @minor = 0; @patch = 0
  32. elsif ARGV.include?("--minor")
  33. @minor = @minor.to_i.next; @patch = 0
  34. else
  35. @patch = @patch.to_i.next
  36. end
  37.  
  38. new_version = [@major, @minor, @patch].join(separator)
  39. puts "CURRENT VERSION: #{current_version}" if verbose
  40. puts "NEW VERSION: #{new_version}"
  41.  
  42. unless ARGV.include?("--dry")
  43. _command = "git tag -m '#{new_version}' #{new_version}"
  44. puts "--> #{_command}" if verbose
  45. system(_command)
  46.  
  47. _command = "git push --tags"
  48. puts "--> #{_command}" if verbose
  49. system(_command)
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement