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