I am following the steps outlined in the below link to ensure that my hooks are rerun every time upon git init
:
Getting started with Ctags with Vim and Git.
Since I don't have fish
installed, I replaced the function git-reload-hooks-all.fish
in the link with the following bash script:
#!/bin/bash
read -rp "Enter repo: " repo
cd "$repo/.git/hooks" || exit
rm -fv ./*
cp ~/.git_template/hooks/* .
cd "$GITWORKSPACE/$repo" || exit
git init
$GITWORKSPACE
in my set up points to the top-level directory that contains all the individual git repositories.
When I execute the script for a chosen git repository under $GITWORKSPACE
, it runs successfully and I can see the following message printed on the terminal:
Reinitialized existing git repository in $GITWORKSPACE/$repo/.git
Note that the variables are replaced by the actual paths in the above output.
I can also see that ./git/hooks/
folder has been updated with the hooks I want.
However, the ctags
hook outlined in the link above has not been run, and I cannot see any .tag
file under $GITWORKSPACE/$repo/
path.
Can someone tell me why git init fails to rerun the hooks?
TIA
As the tutorial says, ctags
is called in the hooks post-checkout
, post-commit
, post-merge
, post-rewrite
.
#!/bin/sh
dir=$(git rev-parse --git-dir)
$dir/hooks/ctags >/dev/null 2>&1 &
git init
does not invoke any of these hooks. As the hook names suggest, they are invoked by other commands. And, post
indicates it runs after the command finishes. The post
family cannot affect the exit code of the command. For example, post-checkout
is invoked by git checkout
or git switch
. You can find the details in githooks.
You can try git checkout
, git commit
, git merge
and git rebase
to test if ctags
runs as expected.