blob: 6f3a0bbd8f8fa2e6c87a6d642d1185b3fcc7ec06 [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 Driessen186d2b52010-01-27 23:48:39 +010016 echo "usage: git flow feature"
17 echo " git flow feature start <name> [<base>]"
18 echo " git flow feature finish <name> [<base>]"
19 echo " git flow feature publish <name>"
20 echo " git flow feature track <name>"
21 echo " git flow feature diff <name>"
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 "--rebase Rebases the feature branch on top of develop, instead of merging"
32 #echo "--squash Squashes all commits of the feature branch into a single commit"
33 #echo " on develop"
34 #echo "--push Push to the origin repo when finished"
35}
36
37parse_args() {
38 NAME="$1"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010039 BASE="${2:-$DEVELOP_BRANCH}"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010040 if [ "$NAME" = "" ]; then
41 echo "Missing argument <name>."
42 usage
43 exit 1
44 fi
Benedikt Böhm96f44c02010-01-26 13:09:32 +010045 PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
46 BRANCH=$PREFIX$NAME
Benedikt Böhm00ccea62010-01-26 12:39:36 +010047}
48
Vincent Driessen186d2b52010-01-27 23:48:39 +010049cmd_default() {
Vincent Driessen170dc742010-01-28 00:20:51 +010050 # TODO: Refactor getting this prefix into a general function
51 PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
Vincent Driessen186d2b52010-01-27 23:48:39 +010052 FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
53 if [ -z "$FEATURE_BRANCHES" ]; then
54 warn "No feature branches exist."
55 exit 0
56 fi
57 echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g"
58}
59
Benedikt Böhm00ccea62010-01-26 12:39:36 +010060cmd_help() {
61 usage
62 exit 0
63}
64
65cmd_start() {
66 parse_args "$@"
67
68 # sanity checks
69 gitflow_check_clean_working_tree
70 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010071 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm4d222272010-01-26 14:46:56 +010072 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm350e7152010-01-26 13:05:05 +010073 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010074 fi
75
76 # create branch
77 git checkout -b $BRANCH $BASE
78
79 echo
80 echo "Summary of actions:"
81 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
82 echo "- You are now on branch '$BRANCH'"
83 echo ""
84 echo "Now, start committing on your feature. When done, use:"
85 echo ""
86 echo " git flow finish feature $NAME"
87 echo
88}
89
90cmd_finish() {
91 parse_args "$@"
92
93 # sanity checks
94 gitflow_check_clean_working_tree
95 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +010096 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010097 if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then
98 gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010099 fi
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100100 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm350e7152010-01-26 13:05:05 +0100101 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100102 fi
103
104 # merge into BASE
105 git checkout $BASE
106 if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then
107 git merge --ff $BRANCH
108 else
109 git merge --no-ff $BRANCH
110 fi
111
112 # delete branch
113 # TODO: How do we handle merge conflicts here??
Benedikt Böhm350e7152010-01-26 13:05:05 +0100114 git push $ORIGIN :refs/heads/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100115 git branch -d $BRANCH
116
117 echo
118 echo "Summary of actions:"
119 echo "- The feature branch '$BRANCH' was merged into '$BASE'"
120 #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
121 echo "- Feature branch '$BRANCH' has been removed"
122 echo "- You are now on branch '$BASE'"
123 echo
124}
125
126cmd_publish() {
127 parse_args "$@"
128
129 # sanity checks
130 gitflow_check_clean_working_tree
131 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100132 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100133 gitflow_require_branch_absent $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100134
135 # create remote branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100136 git push $ORIGIN $BRANCH:refs/heads/$BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100137 git fetch -q $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100138
139 # configure remote tracking
Benedikt Böhm350e7152010-01-26 13:05:05 +0100140 git config branch.$BRANCH.remote $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100141 git config branch.$BRANCH.merge refs/heads/$BRANCH
142 git checkout $BRANCH
143
144 echo
145 echo "Summary of actions:"
146 echo "- A new remote branch '$BRANCH' was created"
147 echo "- The local branch '$BRANCH' was configured to track the remote branch"
148 echo "- You are now on branch '$BRANCH'"
149 echo
150}
151
152cmd_track() {
153 parse_args "$@"
154
155 # sanity checks
156 gitflow_check_clean_working_tree
157 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100158 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100159 gitflow_require_branch $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100160
161 # create tracking branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100162 git checkout -b $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100163
164 echo
165 echo "Summary of actions:"
166 echo "- A new remote tracking branch '$BRANCH' was created"
167 echo "- You are now on branch '$BRANCH'"
168 echo
169}
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100170
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100171cmd_diff() {
172 parse_args "$@"
173 # TODO: if this feature has been based on a non-develop branch, we really
174 # should not be comparing to $DEVELOP. How to deal with this?
175 git diff $DEVELOP..$BRANCH
176}