blob: 51ca9e15b5e8a441dca89e31ea63ef6126be3933 [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
Vincent Driessenab3dc492010-01-29 12:35:49 +010015VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010016PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
Vincent Driessen2acfffd2010-01-29 12:37:22 +010017FLAG_FETCH=1
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010018
Benedikt Böhm00ccea62010-01-26 12:39:36 +010019usage() {
Vincent Driessenb866b012010-01-28 01:01:53 +010020 echo "usage: git flow hotfix [list]"
Vincent Driessen186d2b52010-01-27 23:48:39 +010021 echo " git flow hotfix start <version> [<base>]"
22 echo " git flow hotfix finish <version> [<base>]"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010023 # TODO
24 #echo ""
25 #echo "options:"
26 #echo "--option Explanation"
27 #echo ""
28 #echo "start-only options:"
29 #echo "--option Explanation"
30 #echo ""
31 #echo "finish-only options:"
32 #echo "--push Push to the origin repo when finished"
33}
34
Vincent Driessen186d2b52010-01-27 23:48:39 +010035cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010036 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010037}
38
Vincent Driessenb866b012010-01-28 01:01:53 +010039cmd_list() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010040 HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
41 if [ -z "$HOTFIX_BRANCHES" ]; then
42 warn "No hotfix branches exist."
43 exit 0
44 fi
45 echo "$HOTFIX_BRANCHES" | sed "s?^$PREFIX??g"
46}
47
Benedikt Böhm00ccea62010-01-26 12:39:36 +010048cmd_help() {
49 usage
50 exit 0
51}
52
Vincent Driessenb866b012010-01-28 01:01:53 +010053parse_args() {
Vincent Driessen2acfffd2010-01-29 12:37:22 +010054 # TODO: When we have a nice structured way of parsing flags with getopt,
55 # implement the following flags:
56 # --fetch, to set FLAG_FETCH=1
57 # --no-fetch, to set FLAG_FETCH=0
Vincent Driessenb866b012010-01-28 01:01:53 +010058 VERSION="$1"
59 BASE="${2:-$MASTER_BRANCH}"
60 if [ "$VERSION" = "" ]; then
61 echo "Missing argument <version>."
62 usage
63 exit 1
64 fi
Vincent Driessenb866b012010-01-28 01:01:53 +010065 BRANCH=$PREFIX$VERSION
66}
67
Benedikt Böhm00ccea62010-01-26 12:39:36 +010068cmd_start() {
69 parse_args "$@"
70
71 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +010072 gitflow_require_clean_working_tree
Vincent Driessen2acfffd2010-01-29 12:37:22 +010073 if [ $FLAG_FETCH -eq 1 ]; then
74 git fetch -q $ORIGIN $MASTER_BRANCH
75 fi
Benedikt Böhm350e7152010-01-26 13:05:05 +010076 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010077 gitflow_require_branch_absent $BRANCH
78
79 # create branch
80 git checkout -b $BRANCH $BASE
81
82 echo
83 echo "Summary of actions:"
84 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
85 echo "- You are now on branch '$BRANCH'"
86 echo
87 echo "Follow-up actions:"
88 echo "- Bump the version number now!"
89 echo "- Start committing your hot fixes"
90 echo "- When done, run:"
91 echo
92 echo " git flow finish hotfix '$HOTFIX_BRANCH'"
93 echo
94}
95
96cmd_finish() {
97 parse_args "$@"
98
99 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100100 gitflow_require_clean_working_tree
Vincent Driessen2acfffd2010-01-29 12:37:22 +0100101 if [ $FLAG_FETCH -eq 1 ]; then
102 git fetch -q $ORIGIN $MASTER_BRANCH
103 git fetch -q $ORIGIN $DEVELOP_BRANCH
104 fi
Benedikt Böhm350e7152010-01-26 13:05:05 +0100105 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
106 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100107
108 # merge into BASE
109 git checkout $BASE
110 git merge --no-ff $BRANCH
Vincent Driessenab3dc492010-01-29 12:35:49 +0100111 git tag $VERSION_PREFIX$VERSION
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100112
113 # merge into develop if we fixed a master issue
114 # TODO: merge into support branch
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100115 if [ "$BASE" = "$MASTER_BRANCH" ]; then
116 git checkout $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100117 git merge --no-ff $BRANCH
118 fi
119
120 # delete branch
121 git branch -d $BRANCH
122
123 # TODO: Implement an optional push to master
124 # git push origin develop; git push origin master; git push --tags origin
125
126 echo
127 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100128 echo "- Latest objects have been fetched from '$ORIGIN'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100129 echo "- Hotfix branch has been merged into '$BASE'"
Vincent Driessenab3dc492010-01-29 12:35:49 +0100130 echo "- The hotfix was tagged '$VERSION_PREFIX$VERSION'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100131 if [ "$BASE" = "$MASTER_BRANCH" ]; then
132 echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100133 fi
134 echo "- Hotfix branch '$BRANCH' has been deleted"
135 echo
136}