lib/gitscape/base.rb in gitscape-1.5.7 vs lib/gitscape/base.rb in gitscape-1.6.1

- old
+ new

@@ -79,11 +79,11 @@ options[:push] = false if options[:push].nil? puts `git checkout live` puts `git pull origin` - if hotfix_branch.length == 0 + if hotfix_branch.to_s.length == 0 exception_message = "*** Improper Usage ***\nExpected Usage: hotfix_start <hotfix_name> [--[no-]push]" raise exception_message end hotfix_branch = "hotfix/#{hotfix_branch}" @@ -91,15 +91,15 @@ puts `git checkout -b #{hotfix_branch}` puts `git push origin #{hotfix_branch}` if options[:push] end - def hotfix_finish hotfix_branch=nil, options={:env_depth=>:staging, :push=>true, :update_env=>true} + def hotfix_finish hotfix_branch=nil, options={:env_depth=>:staging, :push=>true, :update_env=>false} # option defaults options[:env_depth] = :staging if options[:env_depth].nil? options[:push] = true if options[:push].nil? - options[:update_env] = true if options[:update_env].nil? + options[:update_env] = false if options[:update_env].nil? usage_string = "expected usage: hotfix_finish [<hotfix_branch>] hotfix_branch: the name of the hotfix branch to finish. if ommitted, you must currently be on a hotfix branch" @@ -289,9 +289,29 @@ if options[:push] && options[:update_env] puts `git push origin live --tags` puts `git push origin master` end + end + + def tag_cleanup options={:push => true} + # Handle default options + options[:push] = true if options[:push].nil? + + # Do a fetch in order to ensure we have all the latest tags + `git fetch` + + # Select which tags to keep. + # We currently keep tags which fulfill any of the following + # 1. starts with 'service/' + # 2. starts with 'rollback-to/' or 'live/', and has an iteration number >= the live_iteration number - 3 + tags = `git tag`.split "\n" + tags_to_delete = tags.select { |tag| !(!/^service\//.match(tag).nil? || /^(?:live|rollback-to)\/i(\d+)/.match(tag).to_a[1].to_i >= live_iteration - 3) } + + puts "Deleting the following tags.\nThese changes #{options[:push] ? "will" : "will not"} be pushed to origin.\n" + + tags_to_delete.each { |tag| puts `git tag -d #{tag}` } + tags_to_delete.each { |tag| puts `git push origin :refs/tags/#{tag}` } if options[:push] end # Returns true if the supplied Git commit hash or reference exists def self.commit_exists?(commit_id) `git rev-parse #{commit_id}`