Commit e93a50b4 authored by Peter van der Does's avatar Peter van der Does Committed by Vincent Driessen

Makes the feature more compliant with nvie comments in #171

Renames the called hooks to new proposed naming convention.
Removes the configurable configuration/hooks directory. All hooks are to be stored in .git/hooks
Signed-off-by: 's avatarPeter van der Does <peter@avirtualhome.com>
Signed-off-by: 's avatarVincent Driessen <vincent@3rdcloud.com>
parent 7c03411a
......@@ -303,48 +303,6 @@ cmd_default() {
git config gitflow.prefix.versiontag "$prefix"
fi
# Ask the user for gitflow configuration directory (main and hooks )
if flag force || \
! git config --get gitflow.dir.main >/dev/null 2>&1 ||
! git config --get gitflow.dir.hooks >/dev/null 2>&1; then
echo
echo "Where is the gitflow directory located?"
fi
local dir
# Main directory
if ! git config --get gitflow.dir.main >/dev/null 2>&1 || flag force; then
default_suggestion=$(git config --get gitflow.dir.main || echo .gitflow/)
printf "gitflow configuration directory? [$default_suggestion] "
if noflag defaults; then
read answer
else
printf "\n"
fi
[ "$answer" = "-" ] && dir= || dir=${answer:-$default_suggestion}
if [ ! -d "$dir" ] ; then
mkdir "$dir" >/dev/null 2>&1 || die "Can not create directory ${dir}"
fi
git config gitflow.dir.main "$dir"
fi
local subdir
# Hooks directory
if ! git config --get gitflow.dir.hooks >/dev/null 2>&1 || flag force; then
default_suggestion=$(git config --get gitflow.dir.hooks || echo hooks/)
printf "gitflow hooks directory? [$default_suggestion] "
if noflag defaults; then
read answer
else
printf "\n"
fi
[ "$answer" = "-" ] && subdir= || subdir=${answer:-$default_suggestion}
if [ ! -d "$dir""$subdir" ] ; then
mkdir -p "$dir""$subdir" >/dev/null 2>&1 || die "Can not create directory ${dir}${subdir}"
fi
git config gitflow.dir.hooks "$subdir"
fi
# TODO: what to do with origin?
}
......
......@@ -175,18 +175,12 @@ gitflow_has_prefixes_configured() {
git config --get gitflow.prefix.versiontag >/dev/null 2>&1
}
gitflow_has_dirs_configured() {
git config --get gitflow.dir.main >/dev/null 2>&1 && \
git config --get gitflow.dir.hooks >/dev/null 2>&1
}
gitflow_is_initialized() {
gitflow_has_master_configured && \
gitflow_has_develop_configured && \
[ "$(git config --get gitflow.branch.master)" != \
"$(git config --get gitflow.branch.develop)" ] && \
gitflow_has_prefixes_configured && \
gitflow_has_dirs_configured
gitflow_has_prefixes_configured
}
# loading settings that can be overridden using git config
......@@ -195,7 +189,7 @@ gitflow_load_settings() {
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)
export GITFLOW_CONF_DIR_HOOKS=$(git config --get gitflow.dir.main)$(git config --get gitflow.dir.hooks)
export GITFLOW_DIR_HOOKS="$DOT_GIT_DIR"/hooks
}
#
......@@ -336,9 +330,9 @@ require_branches_equal() {
# The hooks should return an exit code 0 on success. Any other return code will result in aborting the git flow process.
#
# Naming convention of a hook:
# <prefix>_<SUB COMMAND>_<SUB ACTION>
# <prefix>-flow-<SUB COMMAND>-<SUB ACTION>
# Example for a hook called before the command git flow feature start test is executed:
# pre_feature_start
# pre-flow-feature-start
#
do_hook() {
local prefix="$1"
......@@ -351,12 +345,14 @@ do_hook() {
die "Hook implementation error - Bad Prefix"
fi
if [ -x ${GITFLOW_CONF_DIR_HOOKS}${prefix}_${SUBCOMMAND}_${SUBACTION} ]; then
${GITFLOW_CONF_DIR_HOOKS}${prefix}_${SUBCOMMAND}_${SUBACTION}
if [ -x ${GITFLOW_DIR_HOOKS}${prefix}-flow-${SUBCOMMAND}-${SUBACTION} ]; then
${GITFLOW_DIR_HOOKS}${prefix}-flow-${SUBCOMMAND}-${SUBACTION}
return_code=$?
fi
if [ $return_code -gt 0 ]; then
die "Hook command ${prefix}_${SUBCOMMAND}_${SUBACTION} failed. Exit code $return_code"
if [ $return_code -gt 0 ]; then
die "Hook command ${prefix}-flow-${SUBCOMMAND}-${SUBACTION} failed. Exit code $return_code"
fi
fi
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment