blob: 153c5eaabf78e76335b86ba6032e7e9f49a89dc8 [file] [log] [blame]
Benedikt Böhm00ccea62010-01-26 12:39:36 +01001#
Vincent Driessen6c2d30b2010-01-26 22:18:36 +01002# git-flow -- A collection of Git extensions to provide high-level
3# repository operations for Vincent Driessen's branching model.
Benedikt Böhm00ccea62010-01-26 12:39:36 +01004#
5# Original blog post presenting this model is found at:
6# http://nvie.com/archives/323
7#
8# Feel free to contribute to this project at:
9# http://github.com/nvie/gitflow
10#
11# Copyright (c) 2010 by Vincent Driessen
12# Copyright (c) 2010 by Benedikt Böhm
13#
14
15usage() {
Vincent Driessenb866b012010-01-28 01:01:53 +010016 echo "usage: git flow hotfix [list]"
Vincent Driessen186d2b52010-01-27 23:48:39 +010017 echo " git flow hotfix start <version> [<base>]"
18 echo " git flow hotfix finish <version> [<base>]"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010019 # TODO
20 #echo ""
21 #echo "options:"
22 #echo "--option Explanation"
23 #echo ""
24 #echo "start-only options:"
25 #echo "--option Explanation"
26 #echo ""
27 #echo "finish-only options:"
28 #echo "--push Push to the origin repo when finished"
29}
30
Vincent Driessenb866b012010-01-28 01:01:53 +010031# setup will always be called before the actual cmd_* functions
32setup() {
Benedikt Böhm96f44c02010-01-26 13:09:32 +010033 PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
Benedikt Böhm00ccea62010-01-26 12:39:36 +010034}
35
Vincent Driessen186d2b52010-01-27 23:48:39 +010036cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010037 cmd_list "$@"
38}
39
40cmd_list() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010041 HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
42 if [ -z "$HOTFIX_BRANCHES" ]; then
43 warn "No hotfix branches exist."
44 exit 0
45 fi
46 echo "$HOTFIX_BRANCHES" | sed "s?^$PREFIX??g"
47}
48
Benedikt Böhm00ccea62010-01-26 12:39:36 +010049cmd_help() {
50 usage
51 exit 0
52}
53
Vincent Driessenb866b012010-01-28 01:01:53 +010054parse_args() {
55 VERSION="$1"
56 BASE="${2:-$MASTER_BRANCH}"
57 if [ "$VERSION" = "" ]; then
58 echo "Missing argument <version>."
59 usage
60 exit 1
61 fi
62 PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
63 BRANCH=$PREFIX$VERSION
64}
65
Benedikt Böhm00ccea62010-01-26 12:39:36 +010066cmd_start() {
67 parse_args "$@"
68
69 # sanity checks
70 gitflow_check_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010071 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010072 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010073 gitflow_require_branch_absent $BRANCH
74
75 # create branch
76 git checkout -b $BRANCH $BASE
77
78 echo
79 echo "Summary of actions:"
80 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
81 echo "- You are now on branch '$BRANCH'"
82 echo
83 echo "Follow-up actions:"
84 echo "- Bump the version number now!"
85 echo "- Start committing your hot fixes"
86 echo "- When done, run:"
87 echo
88 echo " git flow finish hotfix '$HOTFIX_BRANCH'"
89 echo
90}
91
92cmd_finish() {
93 parse_args "$@"
94
95 # sanity checks
96 gitflow_check_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010097 git fetch -q $ORIGIN $MASTER_BRANCH
98 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm350e7152010-01-26 13:05:05 +010099 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
100 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100101
102 # merge into BASE
103 git checkout $BASE
104 git merge --no-ff $BRANCH
105 git tag v$VERSION
106
107 # merge into develop if we fixed a master issue
108 # TODO: merge into support branch
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100109 if [ "$BASE" = "$MASTER_BRANCH" ]; then
110 git checkout $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100111 git merge --no-ff $BRANCH
112 fi
113
114 # delete branch
115 git branch -d $BRANCH
116
117 # TODO: Implement an optional push to master
118 # git push origin develop; git push origin master; git push --tags origin
119
120 echo
121 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100122 echo "- Latest objects have been fetched from '$ORIGIN'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100123 echo "- Hotfix branch has been merged into '$BASE'"
124 echo "- The hotfix was tagged 'v$VERSION'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100125 if [ "$BASE" = "$MASTER_BRANCH" ]; then
126 echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100127 fi
128 echo "- Hotfix branch '$BRANCH' has been deleted"
129 echo
130}