blob: 32b1bcccb8e63810fd6c5f166a748e3e44226899 [file] [log] [blame]
Vincent Driessenf7f687c2010-01-21 01:32:18 +01001#!/bin/sh
Vincent Driessen093a1472010-01-21 01:36:44 +01002#
3# gitflow -- A collection of Git wrapper scripts to provide high-level
4# repository operations for Vincent Driessen's branching model:
5#
6# Original blog post presenting this model is found at:
7# http://nvie.com/archives/323
8#
9# Feel free to contribute to this project at:
10# http://github.com/nvie/gitflow
11#
12# Copyright (c) 2010 by Vincent Driessen
13#
Vincent Driessenf7f687c2010-01-21 01:32:18 +010014
15usage() {
Vincent Driessen65cdbb72010-01-26 00:39:27 +010016 echo "usage: gitflow start feature [<options>] <name> [<base>]"
17 echo " gitflow finish feature [<options>] <name>"
18 # TODO
19 #echo ""
20 #echo "options:"
21 #echo "--option Explanation"
22 #echo ""
23 #echo "start-only options:"
24 #echo "--option Explanation"
25 #echo ""
26 #echo "finish-only options:"
27 #echo "--rebase Rebases the feature branch on top of develop, instead of merging"
28 #echo "--squash Squashes all commits of the feature branch into a single commit"
29 #echo " on develop"
30 #echo "--push Push to the origin repo when finished"
Vincent Driessenf7f687c2010-01-21 01:32:18 +010031}
32
33parse_args() {
Vincent Driessenf7f687c2010-01-21 01:32:18 +010034 FEATURE="$1"
Daniel Truemper21c34832010-01-24 12:11:15 +010035 if [ $# -eq 2 ]; then
36 BASE="$2"
37 else
38 BASE="develop"
39 fi
Vincent Driessenf7f687c2010-01-21 01:32:18 +010040 if [ "$FEATURE" = "" ]; then
Vincent Driessen65cdbb72010-01-26 00:39:27 +010041 echo "Missing argument <release>"
Vincent Driessenf7f687c2010-01-21 01:32:18 +010042 usage
43 exit 1
44 fi
45}
46
47start() {
Vincent Driessenf7f687c2010-01-21 01:32:18 +010048 parse_args "$@"
Vincent Driessen3d412552010-01-25 22:16:08 +010049
50 # Checks
Vincent Driessenf7f687c2010-01-21 01:32:18 +010051 gitflow_check_clean_working_tree
Vincent Driessen3d412552010-01-25 22:16:08 +010052 gitflow_require_branch_absent "$FEATURE"
53 if [ "$BASE" = "develop" ]; then
54 gitflow_require_branches_equal 'develop' 'origin/develop'
55 fi
56
57 # All checks passed, ready to roll
Vincent Driessen65cdbb72010-01-26 00:39:27 +010058 git checkout -b "$FEATURE" "$BASE"
59
60 echo ""
61 echo "Summary of actions:"
62 echo "- A new branch '$FEATURE' was created, based on '$BASE'"
63 echo "- You are now on branch '$FEATURE'"
64 echo ""
65 echo "Now, start committing on your feature. When done, use:"
66 echo ""
67 echo " gitflow finish feature '$FEATURE'"
Vincent Driessenf7f687c2010-01-21 01:32:18 +010068}
69
70finish() {
Vincent Driessenf7f687c2010-01-21 01:32:18 +010071 parse_args "$@"
Vincent Driessen3d412552010-01-25 22:16:08 +010072
73 # Checks
Vincent Driessenf7f687c2010-01-21 01:32:18 +010074 gitflow_check_clean_working_tree
Vincent Driessen3d412552010-01-25 22:16:08 +010075 gitflow_require_branch "$FEATURE"
Vincent Driessen65cdbb72010-01-26 00:39:27 +010076 gitflow_require_branches_equal 'develop' 'origin/develop'
Vincent Driessen3d412552010-01-25 22:16:08 +010077
78 # All checks passed, ready to roll
Vincent Driessen65cdbb72010-01-26 00:39:27 +010079 git checkout develop
80 git merge --no-ff "$FEATURE"
81 # TODO: How do we handle merge conflicts here??
82 git branch -d "$FEATURE"
83
84 echo ""
85 echo "Summary of actions:"
86 echo "- The feature branch '$FEATURE' was merged into 'develop'"
87 #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
88 echo "- Feature branch '$FEATURE' has been removed"
89 echo "- You are now on branch 'develop'"
90 echo ""
Vincent Driessenf7f687c2010-01-21 01:32:18 +010091}
92