Skip to content

Commit

Permalink
feat(hooks): add pr#36 automate pre-commit hook
Browse files Browse the repository at this point in the history
Initial feature addition of automating pre-commit hooks installation if
present for git-flow cjs. This is the actual pull request that was
subbmited by [PauloASilva]([email protected])

Closes #36
  • Loading branch information
ChrisJStone committed Jul 13, 2023
2 parents 42ec5a7 + 0edb59f commit 9b7a4eb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions git-flow-init
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}

Expand Down

0 comments on commit 9b7a4eb

Please sign in to comment.