blob: 058a8320d2946544b8c224753453f3c00316763a [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.feature || echo feature/)
16
Benedikt Böhm00ccea62010-01-26 12:39:36 +010017usage() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010018 echo "usage: git flow feature"
19 echo " git flow feature start <name> [<base>]"
20 echo " git flow feature finish <name> [<base>]"
21 echo " git flow feature publish <name>"
22 echo " git flow feature track <name>"
23 echo " git flow feature diff <name>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010024 # TODO
25 #echo ""
26 #echo "options:"
27 #echo "--option Explanation"
28 #echo ""
29 #echo "start-only options:"
30 #echo "--option Explanation"
31 #echo ""
32 #echo "finish-only options:"
33 #echo "--rebase Rebases the feature branch on top of develop, instead of merging"
34 #echo "--squash Squashes all commits of the feature branch into a single commit"
35 #echo " on develop"
36 #echo "--push Push to the origin repo when finished"
37}
38
39parse_args() {
40 NAME="$1"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010041 BASE="${2:-$DEVELOP_BRANCH}"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010042 if [ "$NAME" = "" ]; then
43 echo "Missing argument <name>."
44 usage
45 exit 1
46 fi
Benedikt Böhm96f44c02010-01-26 13:09:32 +010047 BRANCH=$PREFIX$NAME
Benedikt Böhm00ccea62010-01-26 12:39:36 +010048}
49
Vincent Driessen186d2b52010-01-27 23:48:39 +010050cmd_default() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010051 FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
52 if [ -z "$FEATURE_BRANCHES" ]; then
53 warn "No feature branches exist."
54 exit 0
55 fi
56 echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g"
57}
58
Benedikt Böhm00ccea62010-01-26 12:39:36 +010059cmd_help() {
60 usage
61 exit 0
62}
63
64cmd_start() {
65 parse_args "$@"
66
67 # sanity checks
68 gitflow_check_clean_working_tree
69 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010070 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm4d222272010-01-26 14:46:56 +010071 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm350e7152010-01-26 13:05:05 +010072 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010073 fi
74
75 # create branch
76 git checkout -b $BRANCH $BASE
77
78 echo
79 echo "Summary of actions:"
80 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
81 echo "- You are now on branch '$BRANCH'"
82 echo ""
83 echo "Now, start committing on your feature. When done, use:"
84 echo ""
85 echo " git flow finish feature $NAME"
86 echo
87}
88
89cmd_finish() {
90 parse_args "$@"
91
92 # sanity checks
93 gitflow_check_clean_working_tree
94 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +010095 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010096 if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then
97 gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010098 fi
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010099 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm350e7152010-01-26 13:05:05 +0100100 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100101 fi
102
103 # merge into BASE
104 git checkout $BASE
105 if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then
106 git merge --ff $BRANCH
107 else
108 git merge --no-ff $BRANCH
109 fi
110
111 # delete branch
112 # TODO: How do we handle merge conflicts here??
Benedikt Böhm350e7152010-01-26 13:05:05 +0100113 git push $ORIGIN :refs/heads/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100114 git branch -d $BRANCH
115
116 echo
117 echo "Summary of actions:"
118 echo "- The feature branch '$BRANCH' was merged into '$BASE'"
119 #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
120 echo "- Feature branch '$BRANCH' has been removed"
121 echo "- You are now on branch '$BASE'"
122 echo
123}
124
125cmd_publish() {
126 parse_args "$@"
127
128 # sanity checks
129 gitflow_check_clean_working_tree
130 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100131 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100132 gitflow_require_branch_absent $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100133
134 # create remote branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100135 git push $ORIGIN $BRANCH:refs/heads/$BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100136 git fetch -q $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100137
138 # configure remote tracking
Benedikt Böhm350e7152010-01-26 13:05:05 +0100139 git config branch.$BRANCH.remote $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100140 git config branch.$BRANCH.merge refs/heads/$BRANCH
141 git checkout $BRANCH
142
143 echo
144 echo "Summary of actions:"
145 echo "- A new remote branch '$BRANCH' was created"
146 echo "- The local branch '$BRANCH' was configured to track the remote branch"
147 echo "- You are now on branch '$BRANCH'"
148 echo
149}
150
151cmd_track() {
152 parse_args "$@"
153
154 # sanity checks
155 gitflow_check_clean_working_tree
156 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100157 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100158 gitflow_require_branch $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100159
160 # create tracking branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100161 git checkout -b $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100162
163 echo
164 echo "Summary of actions:"
165 echo "- A new remote tracking branch '$BRANCH' was created"
166 echo "- You are now on branch '$BRANCH'"
167 echo
168}
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100169
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100170cmd_diff() {
171 parse_args "$@"
172 # TODO: if this feature has been based on a non-develop branch, we really
173 # should not be comparing to $DEVELOP. How to deal with this?
174 git diff $DEVELOP..$BRANCH
175}