Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 1 | # |
Vincent Driessen | 6c2d30b | 2010-01-26 22:18:36 +0100 | [diff] [blame] | 2 | # git-flow -- A collection of Git extensions to provide high-level |
| 3 | # repository operations for Vincent Driessen's branching model. |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 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() { |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 16 | echo "usage: git flow feature" |
| 17 | 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öhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 22 | # 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 | |
| 37 | parse_args() { |
| 38 | NAME="$1" |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 39 | BASE="${2:-$DEVELOP_BRANCH}" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 40 | if [ "$NAME" = "" ]; then |
| 41 | echo "Missing argument <name>." |
| 42 | usage |
| 43 | exit 1 |
| 44 | fi |
Benedikt Böhm | 96f44c0 | 2010-01-26 13:09:32 +0100 | [diff] [blame] | 45 | PREFIX=$(git config --get gitflow.prefix.feature || echo feature/) |
| 46 | BRANCH=$PREFIX$NAME |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 47 | } |
| 48 | |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 49 | cmd_default() { |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 50 | # TODO: Refactor getting this prefix into a general function |
| 51 | PREFIX=$(git config --get gitflow.prefix.feature || echo feature/) |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 52 | FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")" |
| 53 | if [ -z "$FEATURE_BRANCHES" ]; then |
| 54 | warn "No feature branches exist." |
| 55 | exit 0 |
| 56 | fi |
| 57 | echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g" |
| 58 | } |
| 59 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 60 | cmd_help() { |
| 61 | usage |
| 62 | exit 0 |
| 63 | } |
| 64 | |
| 65 | cmd_start() { |
| 66 | parse_args "$@" |
| 67 | |
| 68 | # sanity checks |
| 69 | gitflow_check_clean_working_tree |
| 70 | gitflow_require_branch_absent $BRANCH |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 71 | if [ "$BASE" = "$DEVELOP_BRANCH" ]; then |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 72 | git fetch -q $ORIGIN $DEVELOP_BRANCH |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 73 | gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 74 | fi |
| 75 | |
| 76 | # create branch |
| 77 | git checkout -b $BRANCH $BASE |
| 78 | |
| 79 | echo |
| 80 | echo "Summary of actions:" |
| 81 | echo "- A new branch '$BRANCH' was created, based on '$BASE'" |
| 82 | echo "- You are now on branch '$BRANCH'" |
| 83 | echo "" |
| 84 | echo "Now, start committing on your feature. When done, use:" |
| 85 | echo "" |
| 86 | echo " git flow finish feature $NAME" |
| 87 | echo |
| 88 | } |
| 89 | |
| 90 | cmd_finish() { |
| 91 | parse_args "$@" |
| 92 | |
| 93 | # sanity checks |
| 94 | gitflow_check_clean_working_tree |
| 95 | gitflow_require_branch $BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 96 | git fetch -q $ORIGIN |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 97 | if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then |
| 98 | gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 99 | fi |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 100 | if [ "$BASE" = "$DEVELOP_BRANCH" ]; then |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 101 | gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 102 | fi |
| 103 | |
| 104 | # merge into BASE |
| 105 | git checkout $BASE |
| 106 | if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then |
| 107 | git merge --ff $BRANCH |
| 108 | else |
| 109 | git merge --no-ff $BRANCH |
| 110 | fi |
| 111 | |
| 112 | # delete branch |
| 113 | # TODO: How do we handle merge conflicts here?? |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 114 | git push $ORIGIN :refs/heads/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 115 | git branch -d $BRANCH |
| 116 | |
| 117 | echo |
| 118 | echo "Summary of actions:" |
| 119 | echo "- The feature branch '$BRANCH' was merged into '$BASE'" |
| 120 | #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported |
| 121 | echo "- Feature branch '$BRANCH' has been removed" |
| 122 | echo "- You are now on branch '$BASE'" |
| 123 | echo |
| 124 | } |
| 125 | |
| 126 | cmd_publish() { |
| 127 | parse_args "$@" |
| 128 | |
| 129 | # sanity checks |
| 130 | gitflow_check_clean_working_tree |
| 131 | gitflow_require_branch $BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 132 | git fetch -q $ORIGIN |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 133 | gitflow_require_branch_absent $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 134 | |
| 135 | # create remote branch |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 136 | git push $ORIGIN $BRANCH:refs/heads/$BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 137 | git fetch -q $ORIGIN |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 138 | |
| 139 | # configure remote tracking |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 140 | git config branch.$BRANCH.remote $ORIGIN |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 141 | git config branch.$BRANCH.merge refs/heads/$BRANCH |
| 142 | git checkout $BRANCH |
| 143 | |
| 144 | echo |
| 145 | echo "Summary of actions:" |
| 146 | echo "- A new remote branch '$BRANCH' was created" |
| 147 | echo "- The local branch '$BRANCH' was configured to track the remote branch" |
| 148 | echo "- You are now on branch '$BRANCH'" |
| 149 | echo |
| 150 | } |
| 151 | |
| 152 | cmd_track() { |
| 153 | parse_args "$@" |
| 154 | |
| 155 | # sanity checks |
| 156 | gitflow_check_clean_working_tree |
| 157 | gitflow_require_branch_absent $BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 158 | git fetch -q $ORIGIN |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 159 | gitflow_require_branch $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 160 | |
| 161 | # create tracking branch |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 162 | git checkout -b $BRANCH $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 163 | |
| 164 | echo |
| 165 | echo "Summary of actions:" |
| 166 | echo "- A new remote tracking branch '$BRANCH' was created" |
| 167 | echo "- You are now on branch '$BRANCH'" |
| 168 | echo |
| 169 | } |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 170 | |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 171 | cmd_diff() { |
| 172 | parse_args "$@" |
| 173 | # TODO: if this feature has been based on a non-develop branch, we really |
| 174 | # should not be comparing to $DEVELOP. How to deal with this? |
| 175 | git diff $DEVELOP..$BRANCH |
| 176 | } |