blob: ef3fac38f475e1e1af116c9b7899c867f57636e1 [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 Driessen57e7bde2010-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/)
17
Benedikt Böhm00ccea62010-01-26 12:39:36 +010018usage() {
Vincent Driessenb866b012010-01-28 01:01:53 +010019 echo "usage: git flow hotfix [list]"
Vincent Driessen186d2b52010-01-27 23:48:39 +010020 echo " git flow hotfix start <version> [<base>]"
21 echo " git flow hotfix finish <version> [<base>]"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010022 # TODO
23 #echo ""
24 #echo "options:"
25 #echo "--option Explanation"
26 #echo ""
27 #echo "start-only options:"
28 #echo "--option Explanation"
29 #echo ""
30 #echo "finish-only options:"
31 #echo "--push Push to the origin repo when finished"
32}
33
Vincent Driessen186d2b52010-01-27 23:48:39 +010034cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010035 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010036}
37
Vincent Driessenb866b012010-01-28 01:01:53 +010038cmd_list() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010039 HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
40 if [ -z "$HOTFIX_BRANCHES" ]; then
41 warn "No hotfix branches exist."
42 exit 0
43 fi
44 echo "$HOTFIX_BRANCHES" | sed "s?^$PREFIX??g"
45}
46
Benedikt Böhm00ccea62010-01-26 12:39:36 +010047cmd_help() {
48 usage
49 exit 0
50}
51
Vincent Driessenb866b012010-01-28 01:01:53 +010052parse_args() {
53 VERSION="$1"
54 BASE="${2:-$MASTER_BRANCH}"
55 if [ "$VERSION" = "" ]; then
56 echo "Missing argument <version>."
57 usage
58 exit 1
59 fi
Vincent Driessenb866b012010-01-28 01:01:53 +010060 BRANCH=$PREFIX$VERSION
61}
62
Benedikt Böhm00ccea62010-01-26 12:39:36 +010063cmd_start() {
64 parse_args "$@"
65
66 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +010067 gitflow_require_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010068 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010069 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010070 gitflow_require_branch_absent $BRANCH
71
72 # create branch
73 git checkout -b $BRANCH $BASE
74
75 echo
76 echo "Summary of actions:"
77 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
78 echo "- You are now on branch '$BRANCH'"
79 echo
80 echo "Follow-up actions:"
81 echo "- Bump the version number now!"
82 echo "- Start committing your hot fixes"
83 echo "- When done, run:"
84 echo
85 echo " git flow finish hotfix '$HOTFIX_BRANCH'"
86 echo
87}
88
89cmd_finish() {
90 parse_args "$@"
91
92 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +010093 gitflow_require_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010094 git fetch -q $ORIGIN $MASTER_BRANCH
95 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm350e7152010-01-26 13:05:05 +010096 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
97 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010098
99 # merge into BASE
100 git checkout $BASE
101 git merge --no-ff $BRANCH
Vincent Driessen57e7bde2010-01-29 12:35:49 +0100102 git tag $VERSION_PREFIX$VERSION
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100103
104 # merge into develop if we fixed a master issue
105 # TODO: merge into support branch
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100106 if [ "$BASE" = "$MASTER_BRANCH" ]; then
107 git checkout $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100108 git merge --no-ff $BRANCH
109 fi
110
111 # delete branch
112 git branch -d $BRANCH
113
114 # TODO: Implement an optional push to master
115 # git push origin develop; git push origin master; git push --tags origin
116
117 echo
118 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100119 echo "- Latest objects have been fetched from '$ORIGIN'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100120 echo "- Hotfix branch has been merged into '$BASE'"
Vincent Driessen57e7bde2010-01-29 12:35:49 +0100121 echo "- The hotfix was tagged '$VERSION_PREFIX$VERSION'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100122 if [ "$BASE" = "$MASTER_BRANCH" ]; then
123 echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100124 fi
125 echo "- Hotfix branch '$BRANCH' has been deleted"
126 echo
127}