blob: 7cc1c775ed15a0374826015b0f25e4ad3158ab89 [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 Driessenb866b012010-01-28 01:01:53 +010018 echo "usage: git flow hotfix [list]"
Vincent Driessen186d2b52010-01-27 23:48:39 +010019 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
Vincent Driessen186d2b52010-01-27 23:48:39 +010033cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010034 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010035}
36
Vincent Driessenb866b012010-01-28 01:01:53 +010037cmd_list() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010038 HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
39 if [ -z "$HOTFIX_BRANCHES" ]; then
40 warn "No hotfix branches exist."
41 exit 0
42 fi
43 echo "$HOTFIX_BRANCHES" | sed "s?^$PREFIX??g"
44}
45
Benedikt Böhm00ccea62010-01-26 12:39:36 +010046cmd_help() {
47 usage
48 exit 0
49}
50
Vincent Driessenb866b012010-01-28 01:01:53 +010051parse_args() {
52 VERSION="$1"
53 BASE="${2:-$MASTER_BRANCH}"
54 if [ "$VERSION" = "" ]; then
55 echo "Missing argument <version>."
56 usage
57 exit 1
58 fi
Vincent Driessenb866b012010-01-28 01:01:53 +010059 BRANCH=$PREFIX$VERSION
60}
61
Benedikt Böhm00ccea62010-01-26 12:39:36 +010062cmd_start() {
63 parse_args "$@"
64
65 # sanity checks
66 gitflow_check_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010067 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010068 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010069 gitflow_require_branch_absent $BRANCH
70
71 # create branch
72 git checkout -b $BRANCH $BASE
73
74 echo
75 echo "Summary of actions:"
76 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
77 echo "- You are now on branch '$BRANCH'"
78 echo
79 echo "Follow-up actions:"
80 echo "- Bump the version number now!"
81 echo "- Start committing your hot fixes"
82 echo "- When done, run:"
83 echo
84 echo " git flow finish hotfix '$HOTFIX_BRANCH'"
85 echo
86}
87
88cmd_finish() {
89 parse_args "$@"
90
91 # sanity checks
92 gitflow_check_clean_working_tree
Benedikt Böhm4d222272010-01-26 14:46:56 +010093 git fetch -q $ORIGIN $MASTER_BRANCH
94 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm350e7152010-01-26 13:05:05 +010095 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
96 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010097
98 # merge into BASE
99 git checkout $BASE
100 git merge --no-ff $BRANCH
101 git tag v$VERSION
102
103 # merge into develop if we fixed a master issue
104 # TODO: merge into support branch
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100105 if [ "$BASE" = "$MASTER_BRANCH" ]; then
106 git checkout $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100107 git merge --no-ff $BRANCH
108 fi
109
110 # delete branch
111 git branch -d $BRANCH
112
113 # TODO: Implement an optional push to master
114 # git push origin develop; git push origin master; git push --tags origin
115
116 echo
117 echo "Summary of actions:"
Benedikt Böhm350e7152010-01-26 13:05:05 +0100118 echo "- Latest objects have been fetched from '$ORIGIN'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100119 echo "- Hotfix branch has been merged into '$BASE'"
120 echo "- The hotfix was tagged 'v$VERSION'"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100121 if [ "$BASE" = "$MASTER_BRANCH" ]; then
122 echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100123 fi
124 echo "- Hotfix branch '$BRANCH' has been deleted"
125 echo
126}