blob: b1e88349791ce66d1ba2f1dfed13b4d94df1945c [file] [log] [blame]
Vincent Driessen61ade552010-01-21 01:28:08 +01001#!/bin/sh
Vincent Driessen093a1472010-01-21 01:36:44 +01002#
3# gitflow -- A collection of Git wrapper scripts to provide high-level
4# repository operations for Vincent Driessen's branching model:
5#
6# Original blog post presenting this model is found at:
7# http://nvie.com/archives/323
8#
9# Feel free to contribute to this project at:
10# http://github.com/nvie/gitflow
11#
12# Copyright (c) 2010 by Vincent Driessen
13#
Vincent Driessen61ade552010-01-21 01:28:08 +010014
15usage() {
16 echo "usage: gitflow start hotfix <release>"
17 echo " gitflow finish hotfix <release>"
Vincent Driessen605b7cd2010-01-26 10:39:10 +010018 # TODO
19 #echo ""
20 #echo "options:"
21 #echo "--option Explanation"
22 #echo ""
23 #echo "start-only options:"
24 #echo "--option Explanation"
25 #echo ""
26 #echo "finish-only options:"
27 #echo "--push Push to the origin repo when finished"
Vincent Driessen61ade552010-01-21 01:28:08 +010028}
29
Vincent Driessenf7f687c2010-01-21 01:32:18 +010030parse_args() {
31 RELEASE="$1"
32 if [ "$RELEASE" = "" ]; then
Vincent Driessen605b7cd2010-01-26 10:39:10 +010033 echo "Missing argument <release>"
Vincent Driessenf7f687c2010-01-21 01:32:18 +010034 usage
35 exit 1
36 fi
Vincent Driessen3d412552010-01-25 22:16:08 +010037 HOTFIX_BRANCH="hotfix-$RELEASE"
Vincent Driessenf7f687c2010-01-21 01:32:18 +010038}
39
Vincent Driessen61ade552010-01-21 01:28:08 +010040start() {
Vincent Driessenf7f687c2010-01-21 01:32:18 +010041 parse_args "$@"
Vincent Driessen3d412552010-01-25 22:16:08 +010042
43 # Checks
Vincent Driessen61ade552010-01-21 01:28:08 +010044 gitflow_check_clean_working_tree
Vincent Driessen3d412552010-01-25 22:16:08 +010045 gitflow_require_branches_equal 'master' 'origin/master'
46 gitflow_require_branch_absent "$HOTFIX_BRANCH"
47
48 # All checks passed, ready to roll
Vincent Driessen605b7cd2010-01-26 10:39:10 +010049 git checkout -b "$HOTFIX_BRANCH" master
50
51 echo ""
52 echo "Summary of actions:"
53 echo "- A new branch '$HOTFIX_BRANCH' was created, based on 'master'"
54 echo "- You are now on branch '$HOTFIX_BRANCH'"
55 echo ""
56 echo "Follow-up actions:"
57 echo "- Bump the version number now!"
58 echo "- Start committing your hot fixes"
59 echo "- When done, run:"
60 echo ""
61 echo " gitflow finish hotfix '$HOTFIX_BRANCH'"
Vincent Driessen61ade552010-01-21 01:28:08 +010062}
63
64finish() {
Vincent Driessenf7f687c2010-01-21 01:32:18 +010065 parse_args "$@"
Vincent Driessen3d412552010-01-25 22:16:08 +010066
67 # Checks
Vincent Driessen61ade552010-01-21 01:28:08 +010068 gitflow_check_clean_working_tree
Vincent Driessen3d412552010-01-25 22:16:08 +010069
Vincent Driessen605b7cd2010-01-26 10:39:10 +010070 git fetch origin develop # TODO: Make a flag to skip these fetches
71 git fetch origin master # TODO: Make a flag to skip these fetches
Vincent Driessen3d412552010-01-25 22:16:08 +010072 gitflow_require_branches_equal 'master' 'origin/master'
73 gitflow_require_branches_equal 'develop' 'origin/develop'
74
75 # All checks passed, ready to roll
Vincent Driessen605b7cd2010-01-26 10:39:10 +010076 git checkout master
77 git merge --no-ff "$HOTFIX_BRANCH"
78 git tag "$RELEASE"
79 git checkout develop
80 git merge --no-ff "$HOTFIX_BRANCH"
81 git branch -d "$HOTFIX_BRANCH"
82
83 # TODO: Implement an optional push to master
84 # git push origin develop; git push origin master; git push --tags origin
85
86 echo ""
87 echo "Summary of actions:"
88 echo "- Latest objects have been fetched from 'origin'"
89 echo "- Hotfix branch has been merged into 'master'"
90 echo "- The hotfix was tagged '$RELEASE'"
91 echo "- Hotfix branch has been back-merged into 'develop'"
92 echo "- Hotfix branch '$HOTFIX_BRANCH' has been deleted"
93 echo ""
Vincent Driessen61ade552010-01-21 01:28:08 +010094}
95