forked from petervanderdoes/gitflow-avh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitmonke-common
810 lines (699 loc) · 19.4 KB
/
gitmonke-common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
# $Id$
# vim:et:ft=sh:sts=2:sw=2
#
# git-flow -- A collection of Git extensions to provide high-level
# repository operations for Vincent Driessen's branching model.
#
# A blog post presenting this model is found at:
# http://blog.avirtualhome.com/development-workflow-using-git/
#
# Feel free to contribute to this project at:
# http://github.com/petervanderdoes/gitflow
#
# Authors:
# Copyright 2012-2019 Peter van der Does. All rights reserved.
#
# Original Author:
# Copyright 2010 Vincent Driessen. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# Common functionality
#
# Shell output
warn() { echo "$@" >&2; }
die() { warn "Fatal: $@"; exit 1; }
die_help() { warn $@; flags_help; exit 1; }
escape() {
echo "$1" | sed 's/\([\.\$\*]\)/\\\1/g'
}
#
# String contains function
# $1 haystack
# $2 Needle
#
contains() {
local return
case $1 in
*$2*)
return=$FLAGS_TRUE
;;
*)
return=$FLAGS_FALSE
;;
esac
return $return
}
# Basic math
min() { [ "$1" -le "$2" ] && echo "$1" || echo "$2"; }
max() { [ "$1" -ge "$2" ] && echo "$1" || echo "$2"; }
# Basic string matching
startswith() { [ "$1" != "${1#$2}" ]; }
endswith() { [ "$1" != "${1%$2}" ]; }
# Convenience functions for checking shFlags flags
flag() { local FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -eq $FLAGS_TRUE ]; }
noflag() { local FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -ne $FLAGS_TRUE ]; }
# check_boolean
# Check if given value can be interpreted as a boolean
#
# This function determines if the passed parameter is a valid boolean value.
#
# Param $1: string Value to check if it's a valid boolean
#
# Return: string FLAGS_TRUE|FLAGS_FALSE|FLAGS_ERROR
# FLAGS_TRUE if the parameter is a boolean TRUE
# FLAGS_FALSE if the parameter is a boolean FALSE
# FLAGS_ERROR if the parameter is not a boolean
#
check_boolean() {
local _return _value
_value="${1}"
case "${_value}" in
${FLAGS_TRUE} | [yY] | [yY][eE][sS] | [tT] | [tT][rR][uU][eE])
_return=${FLAGS_TRUE}
;;
${FLAGS_FALSE} | [nN] | [nN][oO] | [fF] | [fF][aA][lL][sS][eE])
_return=${FLAGS_FALSE}
;;
*)
_return=${FLAGS_ERROR}
;;
esac
unset _value
return ${_return}
}
#
# Git specific common functionality
#
git_local_branches() { git for-each-ref --sort refname --format='%(refname:short)' refs/heads; }
git_remote_branches() { git for-each-ref --sort refname --format='%(refname:short)' refs/remotes; }
git_all_branches() { git for-each-ref --sort refname --format='%(refname:short)' refs/remotes refs/heads; }
git_all_tags() { git for-each-ref --format='%(refname:short)' refs/tags; }
git_local_branches_prefixed() {
[ -z $1 ] && die "Prefix parameter missing." # This should never happen.
git for-each-ref --format='%(refname:short)' refs/heads/$1\* ;
}
git_current_branch() {
local branch_name
branch_name="$(git symbolic-ref --quiet HEAD)"
[ -z $branch_name ] && branch_name="(unnamed branch)" || branch_name="$(git for-each-ref --format='%(refname:short)' $branch_name)"
echo "$branch_name"
}
git_is_clean_working_tree() {
git rev-parse --verify HEAD >/dev/null || exit 1
git update-index -q --ignore-submodules --refresh
# Check for unstaged changes
git diff-files --quiet --ignore-submodules || return 1
# Check for Uncommited changes
git diff-index --cached --quiet --ignore-submodules HEAD -- || return 2
return 0
}
git_repo_is_headless() {
! git rev-parse --quiet --verify HEAD >/dev/null 2>&1
}
git_local_branch_exists() {
[ -n "$1" ] || die "Missing branch name"
[ -n "$(git for-each-ref --format='%(refname:short)' refs/heads/$1)" ]
}
git_remote_branch_exists() {
[ -n "$1" ] || die "Missing branch name"
[ -n "$(git for-each-ref --format='%(refname:short)' refs/remotes/$1)" ]
}
git_remote_branch_delete() {
[ -n "$1" ] || die "Missing branch name"
if git_remote_branch_exists "$ORIGIN/$1"; then
git_do push "$ORIGIN" :"$1" || die "Could not delete the remote $1 in $ORIGIN."
return 0
else
warn "Trying to delete the remote branch $1, but it does not exists in $ORIGIN"
return 1
fi
}
git_branch_exists() {
[ -n "$1" ] || die "Missing branch name"
git_local_branch_exists "$1" || git_remote_branch_exists "$ORIGIN/$1"
}
git_tag_exists() {
[ -n "$1" ] || die "Missing tag name"
[ -n "$(git for-each-ref --format='%(refname:short)' refs/tags/$1)" ]
}
git_config_bool_exists() {
local value
[ -n "$1" ] || die "Missing config option"
value=$(git config --get --bool $1)
[ "$value" = "true" ]
}
#
# git_compare_refs()
#
# Tests whether two references have diverged and need merging
# first. It returns error codes to provide more detail, like so:
#
# 0 References point to the same commit
# 1 First given reference needs fast-forwarding
# 2 Second given reference needs fast-forwarding
# 3 References need a real merge
# 4 There is no merge base, i.e. the references have no common ancestors
#
git_compare_refs() {
local commit1 commit2 base
commit1=$(git rev-parse "$1"^{})
commit2=$(git rev-parse "$2"^{})
if [ "$commit1" != "$commit2" ]; then
base=$(git merge-base "$commit1" "$commit2")
if [ $? -ne 0 ]; then
return 4
elif [ "$commit1" = "$base" ]; then
return 1
elif [ "$commit2" = "$base" ]; then
return 2
else
return 3
fi
else
return 0
fi
}
#
# git_is_branch_merged_into()
#
# Checks whether branch $1 is successfully merged into $2
#
git_is_branch_merged_into() {
local merge_hash base_hash
merge_hash=$(git merge-base "$1"^{} "$2"^{})
base_hash=$(git rev-parse "$1"^{})
# If the hashes are equal, the branches are merged.
[ "$merge_hash" = "$base_hash" ]
}
#
# git_is_ancestor()
#
# This is the same function as git_is_branch_merged_into but
# for readability given a different name.
#
git_is_ancestor() {
git_is_branch_merged_into "$1" "$2"
}
#
# git_fetch_branch()
#
# $1 Origin - Where to fetch from
# $2 Branch - Which branch to fetch
#
# This fetches the given branch from the given origin.
# Instead of storing it in FETCH_HEAD it will be stored in
# refs/remotes/<origin>/<branch>
#
git_fetch_branch() {
local origin branch
[ -n "$1" ] || die "Missing origin"
[ -n "$2" ] || die "Missing branch name"
origin="$1"
branch="$2"
if git_remote_branch_exists "$origin/$branch"; then
git_do fetch -q "$origin" "$branch" || die "Could not fetch $branch from $origin."
else
warn "Trying to fetch branch '$origin/$branch' but it does not exist."
fi
}
#
# gitflow specific common functionality
#
# Function used to check if the repository is git-flow enabled.
gitflow_has_master_configured() {
local master
master=$(git config --get gitflow.branch.master)
[ "$master" != "" ] && git_local_branch_exists "$master"
}
gitflow_has_develop_configured() {
local develop
develop=$(git config --get gitflow.branch.develop)
[ "$develop" != "" ] && git_local_branch_exists "$develop"
}
gitflow_is_initialized() {
gitflow_has_master_configured && \
gitflow_has_develop_configured && \
[ "$(git config --get gitflow.branch.master)" != "$(git config --get gitflow.branch.develop)" ] && \
git config --get-regexp gitflow.prefix >/dev/null 2>&1
}
# Loading settings that can be overridden using git config
gitflow_load_settings() {
export GIT_CURRENT_REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
DOT_GIT_DIR=$(git rev-parse --git-dir)
export DOT_GIT_DIR="$(cd ${DOT_GIT_DIR} >/dev/null 2>&1 && pwd)"
export HOOKS_DIR="$(git config --get gitflow.path.hooks || echo ${DOT_GIT_DIR}/hooks)" # the second option is used to support previous versions of git-flow
export MASTER_BRANCH=$(git config --get gitflow.branch.master)
export DEVELOP_BRANCH=$(git config --get gitflow.branch.develop)
export ORIGIN=$(git config --get gitflow.origin || echo origin)
GITFLOW_CONFIG="$DOT_GIT_DIR/gitflow_config"
if [ -f "$GITFLOW_CONFIG" ]; then # move all settings from old .git/gitflow_config to the local conf.
warn "Migrating old \"$GITFLOW_CONFIG\" to the \"--local\" repo config."
_config_lines=`git config --list --file="$GITFLOW_CONFIG"`;
for _config_line in ${_config_lines}; do
_key=${_config_line%=*}
_value=${_config_line#=*}
git_do config --local gitflow.${_key} ${_value}
done;
mv "$GITFLOW_CONFIG" "$GITFLOW_CONFIG".backup 2>/dev/null
fi
}
#
# gitflow_resolve_nameprefix
#
# Inputs:
# $1 = name prefix to resolve
# $2 = branch prefix to use
#
# Searches branch names from git_local_branches() to look for a unique
# branch name whose name starts with the given name prefix.
#
# There are multiple exit codes possible:
# 0: The unambiguous full name of the branch is written to stdout
# (success)
# 1: No match is found.
# 2: Multiple matches found. These matches are written to stderr
#
gitflow_resolve_nameprefix() {
local name prefix
local match matches num_matches
name=$1
prefix=$2
# first, check if there is a perfect match
if git_local_branch_exists "$prefix$name"; then
echo "$name"
return 0
fi
matches=$(echo "$(git_local_branches)" | grep "^$(escape "$prefix$name")")
num_matches=$(echo "$matches" | wc -l)
if [ -z "$matches" ]; then
# no prefix match, so take it literally
warn "No branches match '$prefix$name*'"
return 1
else
if [ $num_matches -eq 1 ]; then
echo "${matches#$prefix}"
return 0
else
# multiple matches, cannot decide
warn "Multiple branches match prefix '$name':"
for match in $matches; do
warn "- $match"
done
return 2
fi
fi
}
#
# Check if the given branch is a git-flow branch
#
gitflow_is_prefixed_branch() {
local branch return
branch=$1
case $branch in
$(git config --get gitflow.prefix.feature)* | \
$(git config --get gitflow.prefix.bugfix)* | \
$(git config --get gitflow.prefix.release)* | \
$(git config --get gitflow.prefix.hotfix)* | \
$(git config --get gitflow.prefix.support)* )
return=0
;;
*)
return=1
;;
esac
return $return
}
#
# Update the config with the base of a new git-flow branch.
#
# @param $1 Base of the new branch
# @param $2 Name of the branch
#
gitflow_config_set_base_branch() {
local base branch
base=$1
branch=$2
$(git_do config --local "gitflow.branch.$branch.base" $base)
}
#
# Get the base of a branch as set by gitflow_set_branch
#
# @param $1 Name of the branch
# @return string|empty String when a base is found otherwise empty
#
gitflow_config_get_base_branch() {
local branch
branch=$1
echo $(git config --local --get "gitflow.branch.$branch.base")
}
#
# Remove the section that contains the base of a branch as set by gitflow_set_branch
#
# @param $1 Name of the branch
#
gitflow_config_remove_base_section() {
local branch
branch=$1
$(git_do config --local --remove-section "gitflow.branch.$branch" 2>/dev/null)
}
#
# Remove the base of the git-flow branch from the.
# @param $1 Name of the branch
#
gitflow_config_remove_base_branch() {
local base
base=$1
$(git_do config --local --unset "gitflow.branch.$branch.base" 2>/dev/null)
}
#
# Remove the base of the git-flow branch from the.
# @param $1 Name of the branch
#
gitflow_config_rename_sections() {
local new
local old
old=$1
new=$2
$(git_do config --local --rename-section "gitflow.branch.$old" "gitflow.branch.$new" 2>/dev/null)
}
# gitflow_override_flag_boolean()
#
# Override a boolean flag
#
# Param $1: string The name of the config variable e.g. "feature.start.fetch"
# Param $2: string The flag name
#
gitflow_override_flag_boolean() {
local _variable
_variable=$(git config --bool --get gitflow.$1 2>&1)
case $? in
0)
[ "${_variable}" = "true" ] && eval "FLAGS_${2}=${FLAGS_TRUE}" || eval "FLAGS_${2}=${FLAGS_FALSE}"
;;
128)
die "${_variable}"
;;
esac
unset _variable
return ${FLAGS_TRUE}
}
# gitflow_override_flag_string()
#
# Override a string flag
#
# Param $1: string The name of the config variable e.g. "feature.start.fetch"
# Param $2: string The flag name
#
gitflow_override_flag_string() {
local _variable
_variable=$(git config --get gitflow.$1 2>&1)
case $? in
0)
eval "FLAGS_${2}=\"${_variable}\""
;;
esac
unset _variable
return ${FLAGS_TRUE}
}
# gitflow_create_squash_message()
#
# Create the squash message, overriding the one generated by git itself
#
# Param $1: string The line to be added
# Param $2: string The base of the branch that will me merged
# Param $3: string The branch that will be merged.
#
gitflow_create_squash_message() {
echo Squashed commit of the following:
echo
echo $1
echo
git log --no-merges --pretty=medium ^"$2" $3
}
#
# Parameter functions
#
gitflow_require_name_arg() {
if [ "$NAME" = "" ]; then
die_help "Missing argument <name>"
fi
}
gitflow_expand_nameprefix_arg() {
local expanded_name exitcode
gitflow_require_name_arg
expanded_name=$(gitflow_resolve_nameprefix "$NAME" "$PREFIX")
exitcode=$?
case $exitcode in
0)
NAME=$expanded_name
BRANCH=$PREFIX$NAME
;;
*)
exit 1
;;
esac
}
gitflow_require_version_arg() {
if [ "$VERSION" = "" ]; then
die_help "Missing argument <version>"
fi
}
gitflow_expand_versionprefix_arg() {
local expanded_version exitcode
gitflow_require_version_arg
version=$(gitflow_resolve_nameprefix "$VERSION" "$PREFIX")
exitcode=$?
case $exitcode in
0)
VERSION=$version
BRANCH=$PREFIX$VERSION
;;
*)
exit 1
;;
esac
}
gitflow_require_base_arg() {
if [ "$BASE" = "" ]; then
die_help "Missing argument <base>"
fi
}
gitflow_use_current_branch_name() {
local current_branch
current_branch=$(git_current_branch)
if startswith "$current_branch" "$PREFIX"; then
BRANCH=$current_branch
NAME=${BRANCH#$PREFIX}
else
warn "The current HEAD is no ${SUBCOMMAND} branch."
warn "Please specify a <name> argument."
exit 1
fi
}
gitflow_use_current_branch_version() {
local current_branch
current_branch=$(git_current_branch)
if startswith "$current_branch" "$PREFIX"; then
BRANCH=$current_branch
VERSION=${BRANCH#$PREFIX}
else
warn "The current HEAD is no ${SUBCOMMAND} branch."
warn "Please specify a <version> argument."
exit 1
fi
}
gitflow_rename_branch() {
# Parse arguments
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# read arguments into global variables
if [ -z $1 ]; then
NEW_NAME=''
else
NEW_NAME=$1
fi
if [ -z $2 ]; then
NAME=''
else
NAME=$2
fi
BRANCH=${PREFIX}${NAME}
NEW_BRANCH=${PREFIX}${NEW_NAME}
if [ -z "$NEW_NAME" ]; then
die "No new name given."
fi
# Use current branch if no name is given
if [ "$NAME" = "" ]; then
gitflow_use_current_branch_name
fi
# Sanity checks
require_branch "$BRANCH"
require_branch_absent "$NEW_BRANCH"
run_pre_hook "$NAME" "$ORIGIN" "$BRANCH"
git_do branch -m "$BRANCH" "$NEW_BRANCH" || die "Error renaming branch '$BRANCH' to '$NEW_BRANCH'"
gitflow_config_rename_sections "$BRANCH" "$NEW_BRANCH"
run_post_hook "$NAME" "$ORIGIN" "$BRANCH"
echo
echo "Summary of actions:"
echo "- Branch '$BRANCH' has been renamed to '$NEW_BRANCH'."
echo "- You are now on branch '$(git_current_branch)'"
echo
}
#
# Assertions for use in git-flow subcommands
#
require_git_repo() {
git rev-parse 2>/dev/null || die "Not a git repository"
}
require_gitflow_initialized() {
gitflow_is_initialized || die "Not a gitflow-enabled repo yet. Please run 'git monke init' first."
$(git config --get gitflow.prefix.versiontag >/dev/null 2>&1) || die "Version tag not set. Please run 'git monke init'."
}
require_clean_working_tree() {
local result
git_is_clean_working_tree
result=$?
if [ $result -eq 1 ]; then
die "Working tree contains unstaged changes. Aborting."
fi
if [ $result -eq 2 ]; then
die "Index contains uncommited changes. Aborting."
fi
}
require_base_is_local_branch() {
git_local_branch_exists "$1" || die "Base '$1' needs to be a branch. It does not exist and is required."
}
require_local_branch() {
git_local_branch_exists "$1" || die "Local branch '$1' does not exist and is required."
}
require_remote_branch() {
git_remote_branch_exists "$1" || die "Remote branch '$1' does not exist and is required."
}
require_branch() {
git_branch_exists "$1" || die "Branch '$1' does not exist and is required."
}
require_branch_absent() {
git_branch_exists "$1" && die "Branch '$1' already exists. Pick another name."
}
require_local_branch_absent() {
git_local_branch_exists "$1" && die "Branch '$1' already exists. Pick another name."
}
require_tag_absent() {
git_tag_exists "$1" && die "Tag '$1' already exists. Pick another name."
}
require_branches_equal() {
local compare_refs_result
require_local_branch "$1"
require_remote_branch "$2"
git_compare_refs "$1" "$2"
compare_refs_result=$?
if [ $compare_refs_result -gt 0 ]; then
warn "Branches '$1' and '$2' have diverged."
if [ $compare_refs_result -eq 1 ]; then
die "And branch '$1' may be fast-forwarded."
elif [ $compare_refs_result -eq 2 ]; then
# Warn here, since there is no harm in being ahead
warn "And local branch '$1' is ahead of '$2'."
else
die "Branches need merging first."
fi
fi
}
#
# Show commands if flag is set.
#
git_do() {
if flag showcommands; then
echo "git $@" >&2
fi
git "$@"
}
#
# run_filter_hook
#
# Looks for a Git hook script called as defined by the first variable
#
# filter-flow-command
#
# If such a hook script exists and is executable, it is called with the given
# positional arguments.
#
run_filter_hook() {
local command scriptfile return
command=$1
shift
scriptfile="${HOOKS_DIR}/filter-flow-${command}"
if [ -x "$scriptfile" ]; then
return=`$scriptfile "$@"`
if [ $? -eq 127 ]; then
echo "$return"
exit 127
fi
echo $return
else
echo "$@"
fi
}
#
# run_pre_hook
#
# Looks for a Git hook script called
#
# pre-flow-<subcmd>-<subaction>
#
# If such a hook script exists and is executable, it is called with the given
# positional arguments. If its return code non-zero, the git-flow action is
# aborted.
#
run_pre_hook() {
local scriptfile exitcode
scriptfile="${HOOKS_DIR}/pre-flow-${SUBCOMMAND}-${SUBACTION}"
exitcode=0
if [ -x "$scriptfile" ]; then
"$scriptfile" "$@"
exitcode=$?
if [ $exitcode -gt 0 ]; then
die "Hook command $scriptfile ended with exit code $exitcode."
fi
fi
}
#
# run_post_hook
#
# Looks for a Git hook script called
#
# post-flow-<subcmd>-<subaction>
#
# If such a hook script exists and is executable, it is called with the given
# positional arguments. Its return code is ignored.
#
run_post_hook() {
local scriptfile
scriptfile="${HOOKS_DIR}/post-flow-${SUBCOMMAND}-${SUBACTION}"
if [ -x "$scriptfile" ]; then
"$scriptfile" "$@"
fi
}
flags_help() {
eval "$( echo "$OPTIONS_SPEC" | git rev-parse --parseopt -- "-h" || echo exit $? )"
}