blob: b9f18b769a91d39b26c7605ee5330773f53b3f9a [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/)
Vincent Driessene034e4a2010-01-29 12:10:44 +010016FLAG_FETCH=0
Benedikt Böhm49dd62b2010-01-28 00:51:15 +010017
Benedikt Böhm00ccea62010-01-26 12:39:36 +010018usage() {
Vincent Driessenb866b012010-01-28 01:01:53 +010019 echo "usage: git flow feature [list]"
Vincent Driessen186d2b52010-01-27 23:48:39 +010020 echo " git flow feature start <name> [<base>]"
21 echo " git flow feature finish <name> [<base>]"
22 echo " git flow feature publish <name>"
23 echo " git flow feature track <name>"
24 echo " git flow feature diff <name>"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010025 # TODO
26 #echo ""
27 #echo "options:"
28 #echo "--option Explanation"
29 #echo ""
30 #echo "start-only options:"
31 #echo "--option Explanation"
32 #echo ""
33 #echo "finish-only options:"
34 #echo "--rebase Rebases the feature branch on top of develop, instead of merging"
35 #echo "--squash Squashes all commits of the feature branch into a single commit"
36 #echo " on develop"
37 #echo "--push Push to the origin repo when finished"
38}
39
Vincent Driessen186d2b52010-01-27 23:48:39 +010040cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010041 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010042}
43
Vincent Driessenb866b012010-01-28 01:01:53 +010044cmd_list() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010045 FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
46 if [ -z "$FEATURE_BRANCHES" ]; then
47 warn "No feature branches exist."
48 exit 0
49 fi
50 echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g"
51}
52
Benedikt Böhm00ccea62010-01-26 12:39:36 +010053cmd_help() {
54 usage
55 exit 0
56}
57
Vincent Driessenb866b012010-01-28 01:01:53 +010058parse_args() {
Vincent Driessene034e4a2010-01-29 12:10:44 +010059 # TODO: When we have a nice structured way of parsing flags with getopt,
Vincent Driessen2acfffd2010-01-29 12:37:22 +010060 # implement the following flags:
61 # --fetch, to set FLAG_FETCH=1
62 # --no-fetch, to set FLAG_FETCH=0
Vincent Driessenb866b012010-01-28 01:01:53 +010063 NAME="$1"
64 BASE="${2:-$DEVELOP_BRANCH}"
65 if [ "$NAME" = "" ]; then
66 echo "Missing argument <name>."
67 usage
68 exit 1
69 fi
Vincent Driessenb866b012010-01-28 01:01:53 +010070 BRANCH=$PREFIX$NAME
71}
72
Benedikt Böhm00ccea62010-01-26 12:39:36 +010073cmd_start() {
74 parse_args "$@"
75
76 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +010077 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +010078 gitflow_require_branch_absent $BRANCH
Vincent Driessene034e4a2010-01-29 12:10:44 +010079
80 # update the local repo with remote changes, if asked
81 if [ $FLAG_FETCH -eq 1 ]; then
Benedikt Böhm4d222272010-01-26 14:46:56 +010082 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010083 fi
84
Vincent Driessene034e4a2010-01-29 12:10:44 +010085 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
86
Benedikt Böhm00ccea62010-01-26 12:39:36 +010087 # create branch
88 git checkout -b $BRANCH $BASE
89
90 echo
91 echo "Summary of actions:"
92 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
93 echo "- You are now on branch '$BRANCH'"
94 echo ""
95 echo "Now, start committing on your feature. When done, use:"
96 echo ""
97 echo " git flow finish feature $NAME"
98 echo
99}
100
101cmd_finish() {
102 parse_args "$@"
103
104 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100105 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100106 gitflow_require_branch $BRANCH
Vincent Driessene034e4a2010-01-29 12:10:44 +0100107
108 # update local repo with remote changes first, if asked
109 if [ $FLAG_FETCH -eq 1 ]; then
110 git fetch -q $ORIGIN $BRANCH
111 fi
112
Benedikt Böhm350e7152010-01-26 13:05:05 +0100113 if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then
114 gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100115 fi
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100116 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm350e7152010-01-26 13:05:05 +0100117 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100118 fi
119
120 # merge into BASE
121 git checkout $BASE
122 if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then
123 git merge --ff $BRANCH
124 else
125 git merge --no-ff $BRANCH
126 fi
127
128 # delete branch
129 # TODO: How do we handle merge conflicts here??
Benedikt Böhm350e7152010-01-26 13:05:05 +0100130 git push $ORIGIN :refs/heads/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100131 git branch -d $BRANCH
132
133 echo
134 echo "Summary of actions:"
135 echo "- The feature branch '$BRANCH' was merged into '$BASE'"
136 #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
137 echo "- Feature branch '$BRANCH' has been removed"
138 echo "- You are now on branch '$BASE'"
139 echo
140}
141
142cmd_publish() {
143 parse_args "$@"
144
145 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100146 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100147 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100148 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100149 gitflow_require_branch_absent $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100150
151 # create remote branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100152 git push $ORIGIN $BRANCH:refs/heads/$BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100153 git fetch -q $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100154
155 # configure remote tracking
Benedikt Böhm350e7152010-01-26 13:05:05 +0100156 git config branch.$BRANCH.remote $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100157 git config branch.$BRANCH.merge refs/heads/$BRANCH
158 git checkout $BRANCH
159
160 echo
161 echo "Summary of actions:"
162 echo "- A new remote branch '$BRANCH' was created"
163 echo "- The local branch '$BRANCH' was configured to track the remote branch"
164 echo "- You are now on branch '$BRANCH'"
165 echo
166}
167
168cmd_track() {
169 parse_args "$@"
170
171 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100172 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100173 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100174 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100175 gitflow_require_branch $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100176
177 # create tracking branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100178 git checkout -b $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100179
180 echo
181 echo "Summary of actions:"
182 echo "- A new remote tracking branch '$BRANCH' was created"
183 echo "- You are now on branch '$BRANCH'"
184 echo
185}
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100186
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100187cmd_diff() {
188 parse_args "$@"
189 # TODO: if this feature has been based on a non-develop branch, we really
190 # should not be comparing to $DEVELOP. How to deal with this?
Vincent Driessen278884b2010-01-28 16:29:34 +0100191 git diff $DEVELOP_BRANCH..$BRANCH
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100192}