Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate Pre-Commit hook install if it exists on git-flow hooks directory #36

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions git-flow-init
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +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
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?
}

Expand Down