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