Skip to content

Commit cc5382d

Browse files
committed
Merge pull request nvie#99 from josephalevin/gitflow
--- Not sure if its of interest to you, but I implemented a --defaults flag in git-flow-init so the script doesnt have to prompt for branch names. My goal is to now make a change in my gitolite install so every new rep is initialized with the git flow model. Resolves issue 88. Great work on git-flow. Im really liking it. Joseph
2 parents 1b471a6 + d2eccaa commit cc5382d

File tree

1 file changed

+42
-9
lines changed

1 file changed

+42
-9
lines changed

git-flow-init

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#
3838

3939
usage() {
40-
echo "usage: git flow init [-f]"
40+
echo "usage: git flow init [-f] [--defaults]"
4141
}
4242

4343
parse_args() {
@@ -49,8 +49,9 @@ parse_args() {
4949
# Default entry when no SUBACTION is given
5050
cmd_default() {
5151
DEFINE_boolean force false 'force setting of gitflow branches, even if already configured' f
52+
DEFINE_boolean defaults false 'use default branch names' 'defaults'
5253
parse_args "$@"
53-
54+
5455
if ! git rev-parse --git-dir >/dev/null 2>&1; then
5556
git init
5657
else
@@ -101,9 +102,17 @@ cmd_default() {
101102
fi
102103
done
103104
fi
105+
106+
if flag defaults; then
107+
warn "Using default branch names."
108+
fi
104109

105110
printf "Branch name for production releases: [$default_suggestion] "
106-
read answer
111+
if ! flag defaults; then
112+
read answer
113+
else
114+
printf "\n"
115+
fi
107116
master_branch=${answer:-$default_suggestion}
108117

109118
# check existence in case of an already existing repo
@@ -146,7 +155,11 @@ cmd_default() {
146155
fi
147156

148157
printf "Branch name for \"next release\" development: [$default_suggestion] "
149-
read answer
158+
if ! flag defaults; then
159+
read answer
160+
else
161+
printf "\n"
162+
fi
150163
develop_branch=${answer:-$default_suggestion}
151164

152165
if [ "$master_branch" = "$develop_branch" ]; then
@@ -216,7 +229,11 @@ cmd_default() {
216229
if ! git config --get gitflow.prefix.feature >/dev/null 2>&1 || flag force; then
217230
default_suggestion=$(git config --get gitflow.prefix.feature || echo feature/)
218231
printf "Feature branches? [$default_suggestion] "
219-
read answer
232+
if ! flag defaults; then
233+
read answer
234+
else
235+
printf "\n"
236+
fi
220237
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
221238
git config gitflow.prefix.feature "$prefix"
222239
fi
@@ -225,7 +242,11 @@ cmd_default() {
225242
if ! git config --get gitflow.prefix.release >/dev/null 2>&1 || flag force; then
226243
default_suggestion=$(git config --get gitflow.prefix.release || echo release/)
227244
printf "Release branches? [$default_suggestion] "
228-
read answer
245+
if ! flag defaults; then
246+
read answer
247+
else
248+
printf "\n"
249+
fi
229250
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
230251
git config gitflow.prefix.release "$prefix"
231252
fi
@@ -235,7 +256,11 @@ cmd_default() {
235256
if ! git config --get gitflow.prefix.hotfix >/dev/null 2>&1 || flag force; then
236257
default_suggestion=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
237258
printf "Hotfix branches? [$default_suggestion] "
238-
read answer
259+
if ! flag defaults; then
260+
read answer
261+
else
262+
printf "\n"
263+
fi
239264
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
240265
git config gitflow.prefix.hotfix "$prefix"
241266
fi
@@ -245,7 +270,11 @@ cmd_default() {
245270
if ! git config --get gitflow.prefix.support >/dev/null 2>&1 || flag force; then
246271
default_suggestion=$(git config --get gitflow.prefix.support || echo support/)
247272
printf "Support branches? [$default_suggestion] "
248-
read answer
273+
if ! flag defaults; then
274+
read answer
275+
else
276+
printf "\n"
277+
fi
249278
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
250279
git config gitflow.prefix.support "$prefix"
251280
fi
@@ -255,7 +284,11 @@ cmd_default() {
255284
if ! git config --get gitflow.prefix.versiontag >/dev/null 2>&1 || flag force; then
256285
default_suggestion=$(git config --get gitflow.prefix.versiontag || echo "")
257286
printf "Version tag prefix? [$default_suggestion] "
258-
read answer
287+
if ! flag defaults; then
288+
read answer
289+
else
290+
printf "\n"
291+
fi
259292
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
260293
git config gitflow.prefix.versiontag "$prefix"
261294
fi

0 commit comments

Comments
 (0)