blob: 8060d47f48fad110f178b9f0c9791991f090bfaa [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 Driessenb866b012010-01-28 01:01:53 +010016 echo "usage: git flow feature [list]"
Vincent Driessen186d2b52010-01-27 23:48:39 +010017 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
Vincent Driessenb866b012010-01-28 01:01:53 +010037# setup will always be called before the actual cmd_* functions
38setup() {
Benedikt Böhm96f44c02010-01-26 13:09:32 +010039 PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
Benedikt Böhm00ccea62010-01-26 12:39:36 +010040}
41
Vincent Driessen186d2b52010-01-27 23:48:39 +010042cmd_default() {
Vincent Driessenb866b012010-01-28 01:01:53 +010043 cmd_list "$@"
44}
45
46cmd_list() {
Vincent Driessen186d2b52010-01-27 23:48:39 +010047 FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
48 if [ -z "$FEATURE_BRANCHES" ]; then
49 warn "No feature branches exist."
50 exit 0
51 fi
52 echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g"
53}
54
Benedikt Böhm00ccea62010-01-26 12:39:36 +010055cmd_help() {
56 usage
57 exit 0
58}
59
Vincent Driessenb866b012010-01-28 01:01:53 +010060parse_args() {
61 NAME="$1"
62 BASE="${2:-$DEVELOP_BRANCH}"
63 if [ "$NAME" = "" ]; then
64 echo "Missing argument <name>."
65 usage
66 exit 1
67 fi
68 PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
69 BRANCH=$PREFIX$NAME
70}
71
Benedikt Böhm00ccea62010-01-26 12:39:36 +010072cmd_start() {
73 parse_args "$@"
74
75 # sanity checks
76 gitflow_check_clean_working_tree
77 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010078 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm4d222272010-01-26 14:46:56 +010079 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm350e7152010-01-26 13:05:05 +010080 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010081 fi
82
83 # create branch
84 git checkout -b $BRANCH $BASE
85
86 echo
87 echo "Summary of actions:"
88 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
89 echo "- You are now on branch '$BRANCH'"
90 echo ""
91 echo "Now, start committing on your feature. When done, use:"
92 echo ""
93 echo " git flow finish feature $NAME"
94 echo
95}
96
97cmd_finish() {
98 parse_args "$@"
99
100 # sanity checks
101 gitflow_check_clean_working_tree
102 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100103 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100104 if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then
105 gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100106 fi
Benedikt Böhm4a864fb2010-01-26 12:59:27 +0100107 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm350e7152010-01-26 13:05:05 +0100108 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100109 fi
110
111 # merge into BASE
112 git checkout $BASE
113 if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then
114 git merge --ff $BRANCH
115 else
116 git merge --no-ff $BRANCH
117 fi
118
119 # delete branch
120 # TODO: How do we handle merge conflicts here??
Benedikt Böhm350e7152010-01-26 13:05:05 +0100121 git push $ORIGIN :refs/heads/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100122 git branch -d $BRANCH
123
124 echo
125 echo "Summary of actions:"
126 echo "- The feature branch '$BRANCH' was merged into '$BASE'"
127 #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
128 echo "- Feature branch '$BRANCH' has been removed"
129 echo "- You are now on branch '$BASE'"
130 echo
131}
132
133cmd_publish() {
134 parse_args "$@"
135
136 # sanity checks
137 gitflow_check_clean_working_tree
138 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100139 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100140 gitflow_require_branch_absent $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100141
142 # create remote branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100143 git push $ORIGIN $BRANCH:refs/heads/$BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100144 git fetch -q $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100145
146 # configure remote tracking
Benedikt Böhm350e7152010-01-26 13:05:05 +0100147 git config branch.$BRANCH.remote $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100148 git config branch.$BRANCH.merge refs/heads/$BRANCH
149 git checkout $BRANCH
150
151 echo
152 echo "Summary of actions:"
153 echo "- A new remote branch '$BRANCH' was created"
154 echo "- The local branch '$BRANCH' was configured to track the remote branch"
155 echo "- You are now on branch '$BRANCH'"
156 echo
157}
158
159cmd_track() {
160 parse_args "$@"
161
162 # sanity checks
163 gitflow_check_clean_working_tree
164 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100165 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100166 gitflow_require_branch $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100167
168 # create tracking branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100169 git checkout -b $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100170
171 echo
172 echo "Summary of actions:"
173 echo "- A new remote tracking branch '$BRANCH' was created"
174 echo "- You are now on branch '$BRANCH'"
175 echo
176}
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100177
Vincent Driessenbd4f0952010-01-27 13:57:15 +0100178cmd_diff() {
179 parse_args "$@"
180 # TODO: if this feature has been based on a non-develop branch, we really
181 # should not be comparing to $DEVELOP. How to deal with this?
182 git diff $DEVELOP..$BRANCH
183}