Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
Makes the feature more compliant with nvie comments in #171
Browse files Browse the repository at this point in the history
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: Peter van der Does <[email protected]>
  • Loading branch information
petervanderdoes committed Jan 2, 2012
1 parent 6ec1707 commit 02200f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 57 deletions.
42 changes: 0 additions & 42 deletions git-flow-init
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}

Expand Down
26 changes: 11 additions & 15 deletions gitflow-common
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

#
Expand Down Expand Up @@ -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"
Expand All @@ -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

}

0 comments on commit 02200f0

Please sign in to comment.