Skip to content

Commit

Permalink
allow user to decide whether to install the pre-commit hook
Browse files Browse the repository at this point in the history
default option is "Y" (install the hook).
where --force is used the local pre-commit hook, if some, will be
saved.
  • Loading branch information
PauloASilva committed Aug 11, 2016
1 parent de9158b commit 0edb59f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions git-flow-init
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,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
# 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
# Check whether there's a previous local pre-commit hook
if [ -f "./.git/hooks/pre-commit" ]; then
echo "A backup of your local pre-commit hook will be created."
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
ln -s "$hooks_dir/pre-commit" -t "./.git/hooks" --backup
fi


# TODO: what to do with origin?
}

Expand Down

0 comments on commit 0edb59f

Please sign in to comment.