You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am looking into git hooks to automate the process of setting up custom config paths
when developing and then resetting the paths when pushing back to upstream.
Use-case: doom-nvim
The default of doom-nvim is for user to install to ~/.config/nvim but since I/we
are using Cheovim I do believe that most of us are using a custom installer location.
Therefor, it would be nice to setup post-checkout and pre-push hooks that take care
of modifying the doom root path so that one doesn't need to always update these paths
manually when switching between local dev/personal branch and a, (in my case), temporary
fetch of upstream development in order to apply patch/rebase/cherry-pick commits etc.
This could then be a recommendation in contribution docs to add these two hooks should
one like to.
Note
Personally I have never used hooks before so I am posting my research here. ;)
#> git checkout -
Switched to branch 'molldev'
post-checkout hook
Checkout type: branch
prev HEAD: pr_prep_branch
new HEAD: molldev
Example 2: pre-push
taken from .git/hooks/pre-push.sample
#!/bin/sh# An example hook script to verify what is about to be pushed. Called by "git# push" after it has checked the remote status, but before anything has been# pushed. If this script exits with a non-zero status nothing will be pushed.## This hook is called with the following parameters:## $1 -- Name of the remote to which the push is being done# $2 -- URL to which the push is being done## If pushing without using a named remote those arguments will be equal.## Information about the commits which are being pushed is supplied as lines to# the standard input in the form:## <local ref> <local oid> <remote ref> <remote oid>## This sample shows how to prevent push of commits where the log message starts# with "WIP" (work in progress).
remote="$1"
url="$2"
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]''0')whileread local_ref local_oid remote_ref remote_oid
doiftest"$local_oid" = "$zero"then# Handle delete:elseiftest"$remote_oid" = "$zero"then# New branch, examine all commits
range="$local_oid"else# Update to existing branch, examine new commits
range="$remote_oid..$local_oid"fi# Check for WIP commit
commit=$(git rev-list -n 1 --grep '^WIP'"$range")iftest -n "$commit"thenecho>&2"Found WIP commit in $local_ref, not pushing"exit 1
fifidoneexit 0
The text was updated successfully, but these errors were encountered:
molleweide
changed the title
Manage custom installer path with git post-checkout hooks
GIT HOOKS: manage custom installer paths during development.
Aug 12, 2021
I am looking into git hooks to automate the process of setting up custom config paths
when developing and then resetting the paths when pushing back to upstream.
Use-case: doom-nvim
The default of doom-nvim is for user to install to ~/.config/nvim but since I/we
are using Cheovim I do believe that most of us are using a custom installer location.
Therefor, it would be nice to setup
post-checkout
andpre-push
hooks that take careof modifying the doom root path so that one doesn't need to always update these paths
manually when switching between local dev/personal branch and a, (in my case), temporary
fetch of upstream development in order to apply patch/rebase/cherry-pick commits etc.
This could then be a recommendation in contribution docs to add these two hooks should
one like to.
Note
Personally I have never used hooks before so I am posting my research here. ;)
resources
Below are interesting links that I have found.
resources: post-checkout
https://stackoverflow.com/questions/1011557/is-there-a-way-to-trigger-a-hook-after-a-new-branch-has-been-checked-out-in-git
https://stackoverflow.com/questions/2141492/git-clone-and-post-checkout-hook
https://gist.github.com/lyrixx/5867424
https://gist.github.com/stefansundin/82051ad2c8565999b914
resources: pre-push
https://gist.github.com/mosra/19abea23cdf6b82ce891c9410612e7e1
https://gist.github.com/ashtanko/5f5221262af66d79c775d68d814f4e22
Example 1: post-checkout
do stuff when checking out branch locally
example source
Example:
touch .git/hooks/post-checkout
chmod u+x .git/hooks/post-checkout
Example 2: pre-push
taken from
.git/hooks/pre-push.sample
The text was updated successfully, but these errors were encountered: