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 | VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag) |
| 16 | PREFIX=$(git config --get gitflow.prefix.support || echo support/) |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 17 | FLAG_FETCH=1 |
Benedikt Böhm | 49dd62b | 2010-01-28 00:51:15 +0100 | [diff] [blame] | 18 | |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 19 | warn "note: The support subcommand is still very EXPERIMENTAL!" |
| 20 | warn "note: DO NOT use it in a production situation." |
| 21 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 22 | usage() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 23 | echo "usage: git flow support [list] [-v]" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 24 | echo " git flow support start <version> <base>" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 25 | } |
| 26 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 27 | cmd_default() { |
| 28 | cmd_list "$@" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 29 | } |
| 30 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 31 | cmd_list() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 32 | DEFINE_boolean verbose false 'verbose (more) output' v |
| 33 | parse_args "$@" |
| 34 | |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 35 | SUPPORT_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")" |
| 36 | if [ -z "$SUPPORT_BRANCHES" ]; then |
| 37 | warn "No support branches exist." |
| 38 | exit 0 |
| 39 | fi |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 40 | |
| 41 | CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g') |
| 42 | SHORT_NAMES=$(echo "$SUPPORT_BRANCHES" | sed "s?^$PREFIX??g") |
| 43 | # determine column width first |
| 44 | width=0 |
| 45 | for branch in $SHORT_NAMES; do |
| 46 | len=$(($(echo "$branch" | wc -c) - 1)) |
| 47 | width=$(max $width $len) |
| 48 | done |
| 49 | width=$(($width + 3)) |
| 50 | |
| 51 | for branch in $SHORT_NAMES; do |
| 52 | fullname="$PREFIX$branch" |
| 53 | base=$(git merge-base "$fullname" "$MASTER_BRANCH") |
| 54 | master_sha=$(git rev-parse "$MASTER_BRANCH") |
| 55 | branch_sha=$(git rev-parse "$fullname") |
| 56 | if [ "$fullname" = "$CURRENT_BRANCH" ]; then |
| 57 | printf "* " |
| 58 | else |
| 59 | printf " " |
| 60 | fi |
| 61 | if flag verbose; then |
| 62 | printf "%-${width}s" "$branch" |
| 63 | if [ "$branch_sha" = "$master_sha" ]; then |
| 64 | printf "(no commits yet)" |
| 65 | else |
| 66 | tagname=$(git name-rev --tags --no-undefined --name-only $base) |
| 67 | if [ "$tagname" != "" ]; then |
| 68 | nicename="$tagname" |
| 69 | else |
| 70 | nicename="$(git rev-parse --short $base)" |
| 71 | fi |
| 72 | printf "(based on $nicename)" |
| 73 | fi |
| 74 | else |
| 75 | printf "%s" "$branch" |
| 76 | fi |
| 77 | echo |
| 78 | done |
Vincent Driessen | 170dc74 | 2010-01-28 00:20:51 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 81 | cmd_help() { |
| 82 | usage |
| 83 | exit 0 |
| 84 | } |
| 85 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 86 | parse_args() { |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 87 | # parse options |
| 88 | FLAGS "$@" || exit $? |
| 89 | eval set -- "${FLAGS_ARGV}" |
| 90 | |
| 91 | # read arguments into global variables |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 92 | VERSION="$1" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 93 | BASE="$2" |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 94 | BRANCH=$PREFIX$VERSION |
| 95 | } |
| 96 | |
| 97 | require_version_arg() { |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 98 | if [ "$VERSION" = "" ]; then |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 99 | warn "Missing argument <version>" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 100 | usage |
| 101 | exit 1 |
| 102 | fi |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 103 | } |
| 104 | |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 105 | require_base_arg() { |
| 106 | if [ "$BASE" = "" ]; then |
| 107 | warn "Missing argument <base>" |
| 108 | usage |
| 109 | exit 1 |
| 110 | fi |
| 111 | } |
| 112 | |
| 113 | require_base_is_on_master() { |
| 114 | if ! git branch --contains "$BASE" 2>/dev/null \ |
| 115 | | sed 's/[* ] //g' \ |
| 116 | | grep -q "^$MASTER_BRANCH\$"; then |
| 117 | die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'." |
| 118 | fi |
| 119 | } |
| 120 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 121 | cmd_start() { |
| 122 | parse_args "$@" |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 123 | require_version_arg |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 124 | require_base_arg |
| 125 | require_base_is_on_master |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 126 | |
| 127 | # sanity checks |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 128 | gitflow_require_clean_working_tree |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 129 | |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 130 | # fetch remote changes |
| 131 | if [ $FLAG_FETCH -eq 1 ]; then |
| 132 | git fetch -q $ORIGIN $BASE |
| 133 | fi |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 134 | gitflow_require_branch_absent $BRANCH |
Vincent Driessen | 2acfffd | 2010-01-29 12:37:22 +0100 | [diff] [blame] | 135 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 136 | # create branch |
Vincent Driessen | 3c337fb | 2010-02-04 11:30:18 +0100 | [diff] [blame] | 137 | git checkout -b "$BRANCH" "$BASE" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 138 | |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 139 | echo |
| 140 | echo "Summary of actions:" |
Vincent Driessen | 010252a | 2010-02-04 10:31:29 +0100 | [diff] [blame] | 141 | echo "- A new branch '$BRANCH' was created, based on '$BASE'" |
Benedikt Böhm | 00ccea6 | 2010-01-26 12:39:36 +0100 | [diff] [blame] | 142 | echo "- You are now on branch '$BRANCH'" |
| 143 | echo |
| 144 | } |