blob: 8134605eab25361663ba889aa844d6ac4e70eedd [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
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010015PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
16
Benedikt Böhm00ccea62010-01-26 12:39:36 +010017usage() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010018 echo "usage: git flow hotfix"
19 echo " git flow hotfix start <version> [<base>]"
20 echo " git flow hotfix finish <version> [<base>]"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010021 # TODO
22 #echo ""
23 #echo "options:"
24 #echo "--option Explanation"
25 #echo ""
26 #echo "start-only options:"
27 #echo "--option Explanation"
28 #echo ""
29 #echo "finish-only options:"
30 #echo "--push Push to the origin repo when finished"
31}
32
33parse_args() {
34 VERSION="$1"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010035 BASE="${2:-$MASTER_BRANCH}"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010036 if [ "$VERSION" = "" ]; then
37 echo "Missing argument <version>."
38 usage
39 exit 1
40 fi
Benedikt Böhm96f44c02010-01-26 13:09:32 +010041 BRANCH=$PREFIX$VERSION
Benedikt Böhm00ccea62010-01-26 12:39:36 +010042}
43
Vincent Driessen186d2b52010-01-27 23:48:39 +010044cmd_default() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010045 HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
46 if [ -z "$HOTFIX_BRANCHES" ]; then
47 warn "No hotfix branches exist."
48 exit 0
49 fi
50 echo "$HOTFIX_BRANCHES" | sed "s?^$PREFIX??g"
51}
52
Benedikt Böhm00ccea62010-01-26 12:39:36 +010053cmd_help() {
54 usage
55 exit 0
56}
57
58cmd_start() {
59 parse_args "$@"
60
61 # sanity checks
62 gitflow_check_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010063 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010064 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010065 gitflow_require_branch_absent $BRANCH
66
67 # create branch
68 git checkout -b $BRANCH $BASE
69
70 echo
71 echo "Summary of actions:"
72 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
73 echo "- You are now on branch '$BRANCH'"
74 echo
75 echo "Follow-up actions:"
76 echo "- Bump the version number now!"
77 echo "- Start committing your hot fixes"
78 echo "- When done, run:"
79 echo
80 echo " git flow finish hotfix '$HOTFIX_BRANCH'"
81 echo
82}
83
84cmd_finish() {
85 parse_args "$@"
86
87 # sanity checks
88 gitflow_check_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010089 git fetch -q $ORIGIN $MASTER_BRANCH
90 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm350e7152010-01-26 13:05:05 +010091 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
92 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010093
94 # merge into BASE
95 git checkout $BASE
96 git merge --no-ff $BRANCH
97 git tag v$VERSION
98
99 # merge into develop if we fixed a master issue
100 # TODO: merge into support branch
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100101 if [ "$BASE" = "$MASTER_BRANCH" ]; then
102 git checkout $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100103 git merge --no-ff $BRANCH
104 fi
105
106 # delete branch
107 git branch -d $BRANCH
108
109 # TODO: Implement an optional push to master
110 # git push origin develop; git push origin master; git push --tags origin
111
112 echo
113 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100114 echo "- Latest objects have been fetched from '$ORIGIN'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100115 echo "- Hotfix branch has been merged into '$BASE'"
116 echo "- The hotfix was tagged 'v$VERSION'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100117 if [ "$BASE" = "$MASTER_BRANCH" ]; then
118 echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100119 fi
120 echo "- Hotfix branch '$BRANCH' has been deleted"
121 echo
122}