diff --git a/git-flow-init b/git-flow-init index 0ab7b190..4a5d86d2 100644 --- a/git-flow-init +++ b/git-flow-init @@ -429,6 +429,28 @@ file= use given config file git_do config $gitflow_config_option gitflow.path.hooks "$hooks_dir" fi + # Automate pre-commit hook install if it exists on git-flow hooks directory + hooks_dir=$(git config --get gitflow.path.hooks) + hooks_dir=${hooks_dir%%/} + if [ -f "$hooks_dir/pre-commit" ]; then + DOT_GIT_DIR=$(git rev-parse --git-dir) + LOCAL_GIT_HOOKS_DIR="$DOT_GIT_DIR/hooks" + # Check whether there's a previous local pre-commit hook to backup + if [ -f "$LOCAL_GIT_HOOKS_DIR/pre-commit" ]; then + backup="(local hook will be saved)" + fi + default_suggestion="Y" + printf "Install pre-commit hook%s? [$default_suggestion] " " $backup" + if noflag defaults; then + read answer + else + printf "\n" + fi + if [ "${answer:-$default_suggestion}" = "Y" ]; then + ln -s "$hooks_dir/pre-commit" -t "$LOCAL_GIT_HOOKS_DIR" --backup + fi + fi + # TODO: what to do with origin? }