Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 154 lines (134 sloc) 3.455 kB
00ccea6 @hollow refactor the whole thing
hollow authored
1 #
6c2d30b @nvie Structurally replace gitflow by git-flow, as a true git extension.
authored
2 # git-flow -- A collection of Git extensions to provide high-level
3 # repository operations for Vincent Driessen's branching model.
00ccea6 @hollow refactor the whole thing
hollow authored
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
d72e4ac @nvie Rewrite the way git-flow initialized its variables in git-flow and as…
authored
15 gitflow_require_git_repo
c1598bf @nvie Added function gitflow_require_initialized(), to assert that the gitflow
authored
16 gitflow_require_initialized
d72e4ac @nvie Rewrite the way git-flow initialized its variables in git-flow and as…
authored
17 gitflow_load_settings
49dd62b @hollow refactor git config calls to global variables
hollow authored
18 VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
c1598bf @nvie Added function gitflow_require_initialized(), to assert that the gitflow
authored
19 PREFIX=$(git config --get gitflow.prefix.support)
49dd62b @hollow refactor git config calls to global variables
hollow authored
20
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
21 warn "note: The support subcommand is still very EXPERIMENTAL!"
22 warn "note: DO NOT use it in a production situation."
23
00ccea6 @hollow refactor the whole thing
hollow authored
24 usage() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
25 echo "usage: git flow support [list] [-v]"
010252a @nvie Added an optional <base> argument to all start subactions.
authored
26 echo " git flow support start <version> <base>"
00ccea6 @hollow refactor the whole thing
hollow authored
27 }
28
170dc74 @nvie Refactored the feature, release and support subcommands, too.
authored
29 cmd_default() {
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
30 cmd_list "$@"
00ccea6 @hollow refactor the whole thing
hollow authored
31 }
32
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
33 cmd_list() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
34 DEFINE_boolean verbose false 'verbose (more) output' v
35 parse_args "$@"
36
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
37 local support_branches
38 local current_branch
39 local short_names
21c7aa9 @nvie Don't store remote and local branch names in shell variables, but query
authored
40 support_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
27592dd @nvie Tidy up:
authored
41 if [ -z "$support_branches" ]; then
170dc74 @nvie Refactored the feature, release and support subcommands, too.
authored
42 warn "No support branches exist."
43 exit 0
44 fi
27592dd @nvie Tidy up:
authored
45 current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
6884523 @nvie Use space (' ') instead of '?' as a pattern terminator.
authored
46 short_names=$(echo "$support_branches" | sed "s ^$PREFIX g")
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
47
48 # determine column width first
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
49 local width=0
50 local branch
27592dd @nvie Tidy up:
authored
51 for branch in $short_names; do
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
52 local len=${#branch}
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
53 width=$(max $width $len)
54 done
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
55 width=$(($width+3))
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
56
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
57 local branch
27592dd @nvie Tidy up:
authored
58 for branch in $short_names; do
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
59 local fullname=$PREFIX$branch
60 local base=$(git merge-base "$fullname" "$MASTER_BRANCH")
61 local master_sha=$(git rev-parse "$MASTER_BRANCH")
62 local branch_sha=$(git rev-parse "$fullname")
27592dd @nvie Tidy up:
authored
63 if [ "$fullname" = "$current_branch" ]; then
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
64 printf "* "
65 else
66 printf " "
67 fi
68 if flag verbose; then
69 printf "%-${width}s" "$branch"
70 if [ "$branch_sha" = "$master_sha" ]; then
71 printf "(no commits yet)"
72 else
f46e290 @nvie Replaced all 'typeset' and 'typeset -i' calls by 'local', as adviced on:
authored
73 local tagname=$(git name-rev --tags --no-undefined --name-only "$base")
74 local nicename
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
75 if [ "$tagname" != "" ]; then
c5fcc01 @nvie Do not quote variable assignments.
authored
76 nicename=$tagname
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
77 else
a4dd223 @nvie Quote all variables in function/program arguments.
authored
78 nicename=$(git rev-parse --short "$base")
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
79 fi
80 printf "(based on $nicename)"
81 fi
82 else
83 printf "%s" "$branch"
84 fi
85 echo
86 done
170dc74 @nvie Refactored the feature, release and support subcommands, too.
authored
87 }
88
00ccea6 @hollow refactor the whole thing
hollow authored
89 cmd_help() {
90 usage
91 exit 0
92 }
93
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
94 parse_args() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
95 # parse options
96 FLAGS "$@" || exit $?
97 eval set -- "${FLAGS_ARGV}"
98
99 # read arguments into global variables
c5fcc01 @nvie Do not quote variable assignments.
authored
100 VERSION=$1
101 BASE=$2
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
102 BRANCH=$PREFIX$VERSION
103 }
104
105 require_version_arg() {
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
106 if [ "$VERSION" = "" ]; then
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
107 warn "Missing argument <version>"
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored
108 usage
109 exit 1
110 fi
111 }
112
010252a @nvie Added an optional <base> argument to all start subactions.
authored
113 require_base_arg() {
114 if [ "$BASE" = "" ]; then
115 warn "Missing argument <base>"
116 usage
117 exit 1
118 fi
119 }
120
121 require_base_is_on_master() {
122 if ! git branch --contains "$BASE" 2>/dev/null \
123 | sed 's/[* ] //g' \
124 | grep -q "^$MASTER_BRANCH\$"; then
125 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
126 fi
127 }
128
00ccea6 @hollow refactor the whole thing
hollow authored
129 cmd_start() {
ca73caf @nvie Replaced all old-style flag variables by shFlags-style flag variables.
authored
130 DEFINE_boolean fetch true "fetch from $ORIGIN before performing finish" F
00ccea6 @hollow refactor the whole thing
hollow authored
131 parse_args "$@"
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
132 require_version_arg
010252a @nvie Added an optional <base> argument to all start subactions.
authored
133 require_base_arg
134 require_base_is_on_master
00ccea6 @hollow refactor the whole thing
hollow authored
135
136 # sanity checks
4838644 @nvie Replace gitflow_check_ prefixes by gitflow_require_ prefixes, for con…
authored
137 gitflow_require_clean_working_tree
00ccea6 @hollow refactor the whole thing
hollow authored
138
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored
139 # fetch remote changes
ca73caf @nvie Replaced all old-style flag variables by shFlags-style flag variables.
authored
140 if flag fetch; then
a4dd223 @nvie Quote all variables in function/program arguments.
authored
141 git fetch -q "$ORIGIN" "$BASE"
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored
142 fi
a4dd223 @nvie Quote all variables in function/program arguments.
authored
143 gitflow_require_branch_absent "$BRANCH"
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored
144
00ccea6 @hollow refactor the whole thing
hollow authored
145 # create branch
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored
146 git checkout -b "$BRANCH" "$BASE"
00ccea6 @hollow refactor the whole thing
hollow authored
147
148 echo
149 echo "Summary of actions:"
010252a @nvie Added an optional <base> argument to all start subactions.
authored
150 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
00ccea6 @hollow refactor the whole thing
hollow authored
151 echo "- You are now on branch '$BRANCH'"
152 echo
153 }
Something went wrong with that request. Please try again.