blob: 2a3e39da31cf831718b86f413f065d4772151021 [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 Driessenb866b012010-01-28 01:01:53 +010018 echo "usage: git flow feature [list]"
Vincent Driessen186d2b52010-01-27 23:48:39 +010019 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
Vincent Driessen186d2b52010-01-27 23:48:39 +010039cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010040 cmd_list "$@"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010041}
42
Vincent Driessenb866b012010-01-28 01:01:53 +010043cmd_list() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010044 FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
45 if [ -z "$FEATURE_BRANCHES" ]; then
46 warn "No feature branches exist."
47 exit 0
48 fi
49 echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g"
50}
51
Benedikt Böhm00ccea62010-01-26 12:39:36 +010052cmd_help() {
53 usage
54 exit 0
55}
56
Vincent Driessenb866b012010-01-28 01:01:53 +010057parse_args() {
58 NAME="$1"
59 BASE="${2:-$DEVELOP_BRANCH}"
60 if [ "$NAME" = "" ]; then
61 echo "Missing argument <name>."
62 usage
63 exit 1
64 fi
Vincent Driessenb866b012010-01-28 01:01:53 +010065 BRANCH=$PREFIX$NAME
66}
67
Benedikt Böhm00ccea62010-01-26 12:39:36 +010068cmd_start() {
69 parse_args "$@"
70
71 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +010072 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +010073 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010074 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm4d222272010-01-26 14:46:56 +010075 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm350e7152010-01-26 13:05:05 +010076 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010077 fi
78
79 # create branch
80 git checkout -b $BRANCH $BASE
81
82 echo
83 echo "Summary of actions:"
84 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
85 echo "- You are now on branch '$BRANCH'"
86 echo ""
87 echo "Now, start committing on your feature. When done, use:"
88 echo ""
89 echo " git flow finish feature $NAME"
90 echo
91}
92
93cmd_finish() {
94 parse_args "$@"
95
96 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +010097 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +010098 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +010099 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100100 if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then
101 gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100102 fi
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100103 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm350e7152010-01-26 13:05:05 +0100104 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100105 fi
106
107 # merge into BASE
108 git checkout $BASE
109 if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then
110 git merge --ff $BRANCH
111 else
112 git merge --no-ff $BRANCH
113 fi
114
115 # delete branch
116 # TODO: How do we handle merge conflicts here??
Benedikt Böhm350e7152010-01-26 13:05:05 +0100117 git push $ORIGIN :refs/heads/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100118 git branch -d $BRANCH
119
120 echo
121 echo "Summary of actions:"
122 echo "- The feature branch '$BRANCH' was merged into '$BASE'"
123 #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
124 echo "- Feature branch '$BRANCH' has been removed"
125 echo "- You are now on branch '$BASE'"
126 echo
127}
128
129cmd_publish() {
130 parse_args "$@"
131
132 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100133 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100134 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100135 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100136 gitflow_require_branch_absent $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100137
138 # create remote branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100139 git push $ORIGIN $BRANCH:refs/heads/$BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100140 git fetch -q $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100141
142 # configure remote tracking
Benedikt Böhm350e7152010-01-26 13:05:05 +0100143 git config branch.$BRANCH.remote $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100144 git config branch.$BRANCH.merge refs/heads/$BRANCH
145 git checkout $BRANCH
146
147 echo
148 echo "Summary of actions:"
149 echo "- A new remote branch '$BRANCH' was created"
150 echo "- The local branch '$BRANCH' was configured to track the remote branch"
151 echo "- You are now on branch '$BRANCH'"
152 echo
153}
154
155cmd_track() {
156 parse_args "$@"
157
158 # sanity checks
Vincent Driessen48386442010-01-29 10:30:40 +0100159 gitflow_require_clean_working_tree
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100160 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100161 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100162 gitflow_require_branch $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100163
164 # create tracking branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100165 git checkout -b $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100166
167 echo
168 echo "Summary of actions:"
169 echo "- A new remote tracking branch '$BRANCH' was created"
170 echo "- You are now on branch '$BRANCH'"
171 echo
172}
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100173
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100174cmd_diff() {
175 parse_args "$@"
176 # TODO: if this feature has been based on a non-develop branch, we really
177 # should not be comparing to $DEVELOP. How to deal with this?
Vincent Driessen278884b2010-01-28 16:29:34 +0100178 git diff $DEVELOP_BRANCH..$BRANCH
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100179}