Vincent Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 1 | #!/bin/sh |
Vincent Driessen | 093a147 | 2010-01-21 01:36:44 +0100 | [diff] [blame] | 2 | # |
| 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 Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 14 | |
| 15 | usage() { |
Vincent Driessen | 65cdbb7 | 2010-01-26 00:39:27 +0100 | [diff] [blame] | 16 | 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 Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | parse_args() { |
Vincent Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 34 | FEATURE="$1" |
Daniel Truemper | 21c3483 | 2010-01-24 12:11:15 +0100 | [diff] [blame] | 35 | if [ $# -eq 2 ]; then |
| 36 | BASE="$2" |
| 37 | else |
| 38 | BASE="develop" |
| 39 | fi |
Vincent Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 40 | if [ "$FEATURE" = "" ]; then |
Vincent Driessen | 65cdbb7 | 2010-01-26 00:39:27 +0100 | [diff] [blame] | 41 | echo "Missing argument <release>" |
Vincent Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 42 | usage |
| 43 | exit 1 |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | start() { |
Vincent Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 48 | parse_args "$@" |
Vincent Driessen | 3d41255 | 2010-01-25 22:16:08 +0100 | [diff] [blame] | 49 | |
| 50 | # Checks |
Vincent Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 51 | gitflow_check_clean_working_tree |
Vincent Driessen | 3d41255 | 2010-01-25 22:16:08 +0100 | [diff] [blame] | 52 | 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 Driessen | 65cdbb7 | 2010-01-26 00:39:27 +0100 | [diff] [blame] | 58 | 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 Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | finish() { |
Vincent Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 71 | parse_args "$@" |
Vincent Driessen | 3d41255 | 2010-01-25 22:16:08 +0100 | [diff] [blame] | 72 | |
| 73 | # Checks |
Vincent Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 74 | gitflow_check_clean_working_tree |
Vincent Driessen | 3d41255 | 2010-01-25 22:16:08 +0100 | [diff] [blame] | 75 | gitflow_require_branch "$FEATURE" |
Vincent Driessen | 65cdbb7 | 2010-01-26 00:39:27 +0100 | [diff] [blame] | 76 | gitflow_require_branches_equal 'develop' 'origin/develop' |
Vincent Driessen | 3d41255 | 2010-01-25 22:16:08 +0100 | [diff] [blame] | 77 | |
| 78 | # All checks passed, ready to roll |
Vincent Driessen | 65cdbb7 | 2010-01-26 00:39:27 +0100 | [diff] [blame] | 79 | 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 Driessen | f7f687c | 2010-01-21 01:32:18 +0100 | [diff] [blame] | 91 | } |
| 92 | |