Skip to content

Instantly share code, notes, and snippets.

@tonekk
Created November 17, 2014 22:59
Show Gist options
  • Save tonekk/c5143838b154fc81dfac to your computer and use it in GitHub Desktop.
Save tonekk/c5143838b154fc81dfac to your computer and use it in GitHub Desktop.
#!/bin/sh
export GIT_MERGE_AUTOEDIT=no
ruby 'bin/hotfix.rb'
unset GIT_MERGE_AUTOEDIT
current_branch = `git rev-parse --abbrev-ref HEAD`
# Check if we are already on a hotfix branch
if (current_branch =~ /hotfix/).nil?
#####################
# Hotfix start flow
#####################
version = File.read('VERSION').scan(/(\d+)\.(\d+)\.(\d+)/)[0]
hotfix = Integer(version[2]) + 1
new_version = "#{version[0]}.#{version[1]}.#{hotfix}"
if system("git flow hotfix start #{new_version}")
# Bump version
File.open('VERSION', 'w'){|f| f.write(new_version)}
system('git add VERSION')
system("git commit -m'bumps version to #{new_version}'")
end
else
#####################
# Hotfix finish flow
#####################
# Use last commit message as tag message
last_commit_message = `git log -1 --pretty=%B`.gsub("\n", '')
last_commit_message.gsub!(' ', '_')
version = current_branch.scan(/hotfix\/(.+)/)[0][0]
if system("git flow hotfix finish -m '#{last_commit_message}' '#{version}'")
system('git push --all && git push --tags')
end
end
@tonekk
Copy link
Author

tonekk commented Nov 17, 2014

Create Hotfixes even faster with Git Flow and this script.
Put e.g. in your rails/bin directory (framework dependant), put execute rights on hotfix and then bin/hotfix to start and end a hotfix.
The script assumes you have a file named VERSION in your projects directory.
Edit accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment