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 | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 16 | echo "usage: git flow list feature" |
| 17 | echo " git flow start feature <name> [<base>]" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 18 | echo " git flow finish feature <name> [<base>]" |
| 19 | echo " git flow publish feature <name>" |
| 20 | echo " git flow track feature <name>" |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 21 | echo " git flow diff feature <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 | |
| 49 | cmd_help() { |
| 50 | usage |
| 51 | exit 0 |
| 52 | } |
| 53 | |
| 54 | cmd_start() { |
| 55 | parse_args "$@" |
| 56 | |
| 57 | # sanity checks |
| 58 | gitflow_check_clean_working_tree |
| 59 | gitflow_require_branch_absent $BRANCH |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 60 | if [ "$BASE" = "$DEVELOP_BRANCH" ]; then |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 61 | git fetch -q $ORIGIN $DEVELOP_BRANCH |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 62 | gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 63 | fi |
| 64 | |
| 65 | # create branch |
| 66 | git checkout -b $BRANCH $BASE |
| 67 | |
| 68 | echo |
| 69 | echo "Summary of actions:" |
| 70 | echo "- A new branch '$BRANCH' was created, based on '$BASE'" |
| 71 | echo "- You are now on branch '$BRANCH'" |
| 72 | echo "" |
| 73 | echo "Now, start committing on your feature. When done, use:" |
| 74 | echo "" |
| 75 | echo " git flow finish feature $NAME" |
| 76 | echo |
| 77 | } |
| 78 | |
| 79 | cmd_finish() { |
| 80 | parse_args "$@" |
| 81 | |
| 82 | # sanity checks |
| 83 | gitflow_check_clean_working_tree |
| 84 | gitflow_require_branch $BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 85 | git fetch -q $ORIGIN |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 86 | if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then |
| 87 | gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 88 | fi |
Benedikt Böhm | 4a864fb | 2010-01-26 12:59:27 +0100 | [diff] [blame] | 89 | if [ "$BASE" = "$DEVELOP_BRANCH" ]; then |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 90 | gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 91 | fi |
| 92 | |
| 93 | # merge into BASE |
| 94 | git checkout $BASE |
| 95 | if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then |
| 96 | git merge --ff $BRANCH |
| 97 | else |
| 98 | git merge --no-ff $BRANCH |
| 99 | fi |
| 100 | |
| 101 | # delete branch |
| 102 | # TODO: How do we handle merge conflicts here?? |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 103 | git push $ORIGIN :refs/heads/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 104 | git branch -d $BRANCH |
| 105 | |
| 106 | echo |
| 107 | echo "Summary of actions:" |
| 108 | echo "- The feature branch '$BRANCH' was merged into '$BASE'" |
| 109 | #echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported |
| 110 | echo "- Feature branch '$BRANCH' has been removed" |
| 111 | echo "- You are now on branch '$BASE'" |
| 112 | echo |
| 113 | } |
| 114 | |
| 115 | cmd_publish() { |
| 116 | parse_args "$@" |
| 117 | |
| 118 | # sanity checks |
| 119 | gitflow_check_clean_working_tree |
| 120 | gitflow_require_branch $BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 121 | git fetch -q $ORIGIN |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 122 | gitflow_require_branch_absent $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 123 | |
| 124 | # create remote branch |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 125 | git push $ORIGIN $BRANCH:refs/heads/$BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 126 | git fetch -q $ORIGIN |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 127 | |
| 128 | # configure remote tracking |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 129 | git config branch.$BRANCH.remote $ORIGIN |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 130 | git config branch.$BRANCH.merge refs/heads/$BRANCH |
| 131 | git checkout $BRANCH |
| 132 | |
| 133 | echo |
| 134 | echo "Summary of actions:" |
| 135 | echo "- A new remote branch '$BRANCH' was created" |
| 136 | echo "- The local branch '$BRANCH' was configured to track the remote branch" |
| 137 | echo "- You are now on branch '$BRANCH'" |
| 138 | echo |
| 139 | } |
| 140 | |
| 141 | cmd_track() { |
| 142 | parse_args "$@" |
| 143 | |
| 144 | # sanity checks |
| 145 | gitflow_check_clean_working_tree |
| 146 | gitflow_require_branch_absent $BRANCH |
Benedikt Böhm | 4d22227 | 2010-01-26 14:46:56 +0100 | [diff] [blame] | 147 | git fetch -q $ORIGIN |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 148 | gitflow_require_branch $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 149 | |
| 150 | # create tracking branch |
Benedikt Böhm | 350e715 | 2010-01-26 13:05:05 +0100 | [diff] [blame] | 151 | git checkout -b $BRANCH $ORIGIN/$BRANCH |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 152 | |
| 153 | echo |
| 154 | echo "Summary of actions:" |
| 155 | echo "- A new remote tracking branch '$BRANCH' was created" |
| 156 | echo "- You are now on branch '$BRANCH'" |
| 157 | echo |
| 158 | } |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 159 | |
| 160 | cmd_list() { |
| 161 | # TODO: refactor this, because passing in this dummy "foo" is really ugly! |
| 162 | parse_args "$@" foo |
| 163 | FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")" |
| 164 | if [ -z "$FEATURE_BRANCHES" ]; then |
| 165 | warn "No feature branches exist." |
Vincent Driessen | c51aedf | 2010-01-27 14:08:50 +0100 | [diff] [blame] | 166 | exit 0 |
Vincent Driessen | bd4f095 | 2010-01-27 13:57:15 +0100 | [diff] [blame] | 167 | fi |
| 168 | echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g" |
| 169 | } |
| 170 | |
| 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 | } |