blob: c4fd814655415bfedf5e5a20e661e058fc0d8fea [file] [log] [blame]
Benedikt Böhm00ccea62010-01-26 12:39:36 +01001#
2# gitflow -- A collection of Git wrapper scripts to provide high-level
3# repository operations for Vincent Driessen's branching model:
4#
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() {
16 echo "usage: git flow start feature <name> [<base>]"
17 echo " git flow finish feature <name> [<base>]"
18 echo " git flow publish feature <name>"
19 echo " git flow track feature <name>"
20 # TODO
21 #echo ""
22 #echo "options:"
23 #echo "--option Explanation"
24 #echo ""
25 #echo "start-only options:"
26 #echo "--option Explanation"
27 #echo ""
28 #echo "finish-only options:"
29 #echo "--rebase Rebases the feature branch on top of develop, instead of merging"
30 #echo "--squash Squashes all commits of the feature branch into a single commit"
31 #echo " on develop"
32 #echo "--push Push to the origin repo when finished"
33}
34
35parse_args() {
36 NAME="$1"
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010037 BASE="${2:-$DEVELOP_BRANCH}"
Benedikt Böhm00ccea62010-01-26 12:39:36 +010038 if [ "$NAME" = "" ]; then
39 echo "Missing argument <name>."
40 usage
41 exit 1
42 fi
Benedikt Böhm96f44c02010-01-26 13:09:32 +010043 PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
44 BRANCH=$PREFIX$NAME
Benedikt Böhm00ccea62010-01-26 12:39:36 +010045}
46
47cmd_help() {
48 usage
49 exit 0
50}
51
52cmd_start() {
53 parse_args "$@"
54
55 # sanity checks
56 gitflow_check_clean_working_tree
57 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010058 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm4d222272010-01-26 14:46:56 +010059 git fetch -q $ORIGIN $DEVELOP_BRANCH
Benedikt Böhm350e7152010-01-26 13:05:05 +010060 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010061 fi
62
63 # create branch
64 git checkout -b $BRANCH $BASE
65
66 echo
67 echo "Summary of actions:"
68 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
69 echo "- You are now on branch '$BRANCH'"
70 echo ""
71 echo "Now, start committing on your feature. When done, use:"
72 echo ""
73 echo " git flow finish feature $NAME"
74 echo
75}
76
77cmd_finish() {
78 parse_args "$@"
79
80 # sanity checks
81 gitflow_check_clean_working_tree
82 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +010083 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +010084 if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then
85 gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010086 fi
Benedikt Böhm4a864fb2010-01-26 12:59:27 +010087 if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
Benedikt Böhm350e7152010-01-26 13:05:05 +010088 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +010089 fi
90
91 # merge into BASE
92 git checkout $BASE
93 if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then
94 git merge --ff $BRANCH
95 else
96 git merge --no-ff $BRANCH
97 fi
98
99 # delete branch
100 # TODO: How do we handle merge conflicts here??
Benedikt Böhm350e7152010-01-26 13:05:05 +0100101 git push $ORIGIN :refs/heads/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100102 git branch -d $BRANCH
103
104 echo
105 echo "Summary of actions:"
106 echo "- The feature branch '$BRANCH' was merged into '$BASE'"
107 #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
108 echo "- Feature branch '$BRANCH' has been removed"
109 echo "- You are now on branch '$BASE'"
110 echo
111}
112
113cmd_publish() {
114 parse_args "$@"
115
116 # sanity checks
117 gitflow_check_clean_working_tree
118 gitflow_require_branch $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100119 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100120 gitflow_require_branch_absent $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100121
122 # create remote branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100123 git push $ORIGIN $BRANCH:refs/heads/$BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100124 git fetch -q $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100125
126 # configure remote tracking
Benedikt Böhm350e7152010-01-26 13:05:05 +0100127 git config branch.$BRANCH.remote $ORIGIN
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100128 git config branch.$BRANCH.merge refs/heads/$BRANCH
129 git checkout $BRANCH
130
131 echo
132 echo "Summary of actions:"
133 echo "- A new remote branch '$BRANCH' was created"
134 echo "- The local branch '$BRANCH' was configured to track the remote branch"
135 echo "- You are now on branch '$BRANCH'"
136 echo
137}
138
139cmd_track() {
140 parse_args "$@"
141
142 # sanity checks
143 gitflow_check_clean_working_tree
144 gitflow_require_branch_absent $BRANCH
Benedikt Böhm4d222272010-01-26 14:46:56 +0100145 git fetch -q $ORIGIN
Benedikt Böhm350e7152010-01-26 13:05:05 +0100146 gitflow_require_branch $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100147
148 # create tracking branch
Benedikt Böhm350e7152010-01-26 13:05:05 +0100149 git checkout -b $BRANCH $ORIGIN/$BRANCH
Benedikt Böhm00ccea62010-01-26 12:39:36 +0100150
151 echo
152 echo "Summary of actions:"
153 echo "- A new remote tracking branch '$BRANCH' was created"
154 echo "- You are now on branch '$BRANCH'"
155 echo
156}