Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 1 | # |
| 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 | |
| 15 | usage() { |
| 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 | |
| 35 | parse_args() { |
| 36 | NAME="$1" |
| 37 | BASE="${2:-develop}" |
| 38 | if [ "$NAME" = "" ]; then |
| 39 | echo "Missing argument <name>." |
| 40 | usage |
| 41 | exit 1 |
| 42 | fi |
| 43 | BRANCH=feature/$NAME |
| 44 | } |
| 45 | |
| 46 | cmd_help() { |
| 47 | usage |
| 48 | exit 0 |
| 49 | } |
| 50 | |
| 51 | cmd_start() { |
| 52 | parse_args "$@" |
| 53 | |
| 54 | # sanity checks |
| 55 | gitflow_check_clean_working_tree |
| 56 | gitflow_require_branch_absent $BRANCH |
| 57 | if [ "$BASE" = "develop" ]; then |
| 58 | git fetch origin develop |
| 59 | gitflow_require_branches_equal develop origin/develop |
| 60 | fi |
| 61 | |
| 62 | # create branch |
| 63 | git checkout -b $BRANCH $BASE |
| 64 | |
| 65 | echo |
| 66 | echo "Summary of actions:" |
| 67 | echo "- A new branch '$BRANCH' was created, based on '$BASE'" |
| 68 | echo "- You are now on branch '$BRANCH'" |
| 69 | echo "" |
| 70 | echo "Now, start committing on your feature. When done, use:" |
| 71 | echo "" |
| 72 | echo " git flow finish feature $NAME" |
| 73 | echo |
| 74 | } |
| 75 | |
| 76 | cmd_finish() { |
| 77 | parse_args "$@" |
| 78 | |
| 79 | # sanity checks |
| 80 | gitflow_check_clean_working_tree |
| 81 | gitflow_require_branch $BRANCH |
| 82 | git fetch origin |
| 83 | if has origin/$BRANCH $REMOTE_BRANCHES; then |
| 84 | gitflow_require_branches_equal $BRANCH origin/$BRANCH |
| 85 | fi |
| 86 | if [ "$BASE" = "develop" ]; then |
| 87 | gitflow_require_branches_equal develop origin/develop |
| 88 | fi |
| 89 | |
| 90 | # merge into BASE |
| 91 | git checkout $BASE |
| 92 | if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then |
| 93 | git merge --ff $BRANCH |
| 94 | else |
| 95 | git merge --no-ff $BRANCH |
| 96 | fi |
| 97 | |
| 98 | # delete branch |
| 99 | # TODO: How do we handle merge conflicts here?? |
| 100 | git push origin :refs/heads/$BRANCH |
| 101 | git branch -d $BRANCH |
| 102 | |
| 103 | echo |
| 104 | echo "Summary of actions:" |
| 105 | echo "- The feature branch '$BRANCH' was merged into '$BASE'" |
| 106 | #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported |
| 107 | echo "- Feature branch '$BRANCH' has been removed" |
| 108 | echo "- You are now on branch '$BASE'" |
| 109 | echo |
| 110 | } |
| 111 | |
| 112 | cmd_publish() { |
| 113 | parse_args "$@" |
| 114 | |
| 115 | # sanity checks |
| 116 | gitflow_check_clean_working_tree |
| 117 | gitflow_require_branch $BRANCH |
| 118 | git fetch origin |
| 119 | gitflow_require_branch_absent origin/$BRANCH |
| 120 | |
| 121 | # create remote branch |
| 122 | git push origin $BRANCH:refs/heads/$BRANCH |
| 123 | git fetch origin |
| 124 | |
| 125 | # configure remote tracking |
| 126 | git config branch.$BRANCH.remote origin |
| 127 | git config branch.$BRANCH.merge refs/heads/$BRANCH |
| 128 | git checkout $BRANCH |
| 129 | |
| 130 | echo |
| 131 | echo "Summary of actions:" |
| 132 | echo "- A new remote branch '$BRANCH' was created" |
| 133 | echo "- The local branch '$BRANCH' was configured to track the remote branch" |
| 134 | echo "- You are now on branch '$BRANCH'" |
| 135 | echo |
| 136 | } |
| 137 | |
| 138 | cmd_track() { |
| 139 | parse_args "$@" |
| 140 | |
| 141 | # sanity checks |
| 142 | gitflow_check_clean_working_tree |
| 143 | gitflow_require_branch_absent $BRANCH |
| 144 | git fetch origin |
| 145 | gitflow_require_branch origin/$BRANCH |
| 146 | |
| 147 | # create tracking branch |
| 148 | git checkout -b $BRANCH origin/$BRANCH |
| 149 | |
| 150 | echo |
| 151 | echo "Summary of actions:" |
| 152 | echo "- A new remote tracking branch '$BRANCH' was created" |
| 153 | echo "- You are now on branch '$BRANCH'" |
| 154 | echo |
| 155 | } |