Avoid to pushing multiple commits by inadvertance
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Fri Apr 26 13:39:34 UTC 2024
Hi!
Since it is Friday, I decided to do something about my tendency to push
several commits by mistake. The attached pre-push hook refuses to push
more than one commit unless the "multi" variable is set.
If you want this hook to be active for all your repositories, you can use
git config --global core.hooksPath /my/hok/dir/
JMarc
-------------- next part --------------
#!/bin/bash
# Git pre-push hook: trigger an error if there are more than one
# commit. It is possible to disable this check by setting the 'multi'
# variable.
# To activate hooks (placed in my case in ~/repo/bin) for a preositories, do
# git config --global core.hooksPath ~/repo/bin/
# Example of stdin when pushing 7a710117 over 66927330:
# refs/heads/master 7a710117bf4437fcbe7f2e76fea049b823e5bb5f refs/heads/master 66927330c90e09b081878cf847aa7d7e38e1db4d
read ref1 hash1 ref2 hash2
ncommits=$(git rev-list --count $hash2..$hash1)
# Now do the actual check
if [[ ${ncommits} > 1 && -z "${multi}" ]]; then
echo "Cannot push ${ncommits} commits."
echo "If you really want to do that, set multi=1"
exit 1
fi
More information about the lyx-devel
mailing list