blob: 663e788c532643f86f74932920ee66c52e71d81c [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 Driessenbd4f0952010-01-27 13:57:15 +010016 echo "usage: git flow list feature"
17 echo " git flow start feature <name> [<base>]"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010018 echo " git flow finish feature <name> [<base>]"
19 echo " git flow publish feature <name>"
20 echo " git flow track feature <name>"
Vincent Driessenbd4f0952010-01-27 13:57:15 +010021 echo " git flow diff feature <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
49cmd_help() {
50 usage
51 exit 0
52}
53
54cmd_start() {
55 parse_args "$@"
56
57 # sanity checks
58 gitflow_check_clean_working_tree
59 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010060 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm4d222272010-01-26 14:46:56 +010061 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm350e7152010-01-26 13:05:05 +010062 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010063 fi
64
65 # create branch
66 git checkout -b $BRANCH $BASE
67
68 echo
69 echo "Summary of actions:"
70 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
71 echo "- You are now on branch '$BRANCH'"
72 echo ""
73 echo "Now, start committing on your feature. When done, use:"
74 echo ""
75 echo " git flow finish feature $NAME"
76 echo
77}
78
79cmd_finish() {
80 parse_args "$@"
81
82 # sanity checks
83 gitflow_check_clean_working_tree
84 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +010085 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010086 if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then
87 gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010088 fi
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010089 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm350e7152010-01-26 13:05:05 +010090 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010091 fi
92
93 # merge into BASE
94 git checkout $BASE
95 if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then
96 git merge --ff $BRANCH
97 else
98 git merge --no-ff $BRANCH
99 fi
100
101 # delete branch
102 # TODO: How do we handle merge conflicts here??
Benedikt Böhm350e7152010-01-26 13:05:05 +0100103 git push $ORIGIN :refs/heads/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100104 git branch -d $BRANCH
105
106 echo
107 echo "Summary of actions:"
108 echo "- The feature branch '$BRANCH' was merged into '$BASE'"
109 #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
110 echo "- Feature branch '$BRANCH' has been removed"
111 echo "- You are now on branch '$BASE'"
112 echo
113}
114
115cmd_publish() {
116 parse_args "$@"
117
118 # sanity checks
119 gitflow_check_clean_working_tree
120 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100121 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100122 gitflow_require_branch_absent $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100123
124 # create remote branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100125 git push $ORIGIN $BRANCH:refs/heads/$BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100126 git fetch -q $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100127
128 # configure remote tracking
Benedikt Böhm350e7152010-01-26 13:05:05 +0100129 git config branch.$BRANCH.remote $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100130 git config branch.$BRANCH.merge refs/heads/$BRANCH
131 git checkout $BRANCH
132
133 echo
134 echo "Summary of actions:"
135 echo "- A new remote branch '$BRANCH' was created"
136 echo "- The local branch '$BRANCH' was configured to track the remote branch"
137 echo "- You are now on branch '$BRANCH'"
138 echo
139}
140
141cmd_track() {
142 parse_args "$@"
143
144 # sanity checks
145 gitflow_check_clean_working_tree
146 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100147 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100148 gitflow_require_branch $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100149
150 # create tracking branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100151 git checkout -b $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100152
153 echo
154 echo "Summary of actions:"
155 echo "- A new remote tracking branch '$BRANCH' was created"
156 echo "- You are now on branch '$BRANCH'"
157 echo
158}
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100159
160cmd_list() {
161 # TODO: refactor this, because passing in this dummy "foo" is really ugly!
162 parse_args "$@" foo
163 FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
164 if [ -z "$FEATURE_BRANCHES" ]; then
165 warn "No feature branches exist."
Vincent Driessenc51aedf2010-01-27 14:08:50 +0100166 exit 0
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100167 fi
168 echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g"
169}
170
171cmd_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}