pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

commit 04bc045017706c6b730cfa9449cb45292b418f3b
parent a1cc80994358bf88d0301e8348a2411bf50814b8
Author: pyratebeard <root@pyratebeard.net>
Date:   Fri, 11 Nov 2022 20:56:00 +0000

what_the_hook

Diffstat:
Mentry/what_the_hook.md | 24++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/entry/what_the_hook.md b/entry/what_the_hook.md @@ -2,13 +2,13 @@ Git [hooks](TK){target="_blank" rel="noreferrer"} are often overlooked or underu While these tips can work for any repo, this could be viewed as an expansion on my [tech_grimoire](20220525-tech_grimoire.html){target="_blank" rel="noreferrer"} post. -For note taking I make use of the [VimWiki](TK){target="_blank" rel="noreferrer"} plugin to Vim. My wiki directory is a git repository, which is then cloned on to one of my servers and using [Gollum](TK){target="_blank" rel="noreferrer"}, available as a website. +For note taking I make use of the [VimWiki](TK){target="_blank" rel="noreferrer"} plugin to Vim. My wiki directory is a git repository, which is then cloned on to one of my servers and using [Gollum](TK){target="_blank" rel="noreferrer"} is available as a website. This has worked well for years, but one thing I have not been good at is committing and pushing changes straight away. In order to improve my workflow I make use of two git hooks, one in the local repo and one in the remote bare repo. Git hooks are scripts which can be run at various times in a git workflow. When they run is based on the name of the script. -If you look in the ".git/hooks" directory of a repo you should see some sample scripts. +If you look in the .git/hooks directory of a repo you should see some sample scripts. ``` ──── ─ ls -1 .git/hooks @@ -33,16 +33,16 @@ For my wiki I make of the `post-commit` hook. git push origin master ``` -That's it. Pretty simple really. All this means is that as soon as I make a commit the master branch is automatically pushed. +That's it. As soon as I make a commit the master branch is automatically pushed. -This works great, but I wanted to go one step further to automatically adding changed files and making the commit. The `prepare-commit-msg` hook is useful when you want to populate the commit message with something, but I couldn't figure out an easy way to do what I wanted with hooks. +This works but I wanted to go one step further, automatically adding changed files and making the commit. The `prepare-commit-msg` hook is useful when you want to populate the commit message with something, but I couldn't figure out an easy way to do what I wanted with hooks. In the end I used a command in my ~/.vimrc ``` set :Gac git commit -a -m "updates" ``` -Now as soon as I have finished updating my wiki I can incant +Now, when I have finished updating my wiki I incant ``` :Gac ``` @@ -55,18 +55,18 @@ Once the changes are pushed to my git server they hit another hook, `post-receiv ssh wikiserver "cd /grimoire ; git pull" ``` -As soon as the remote bare repo receives any updates the hook will perform a `git pull` of my wiki on the server I host it on, causing my Gollum page to be updated instantly. +When the remote bare repo receives any updates the hook will perform a `git pull` of my wiki on the server I host it on, causing my Gollum page to be updated. -The finally thing I have done is to change the hooks directory in my local repo. With the default dir, ".git/hooks", nothing can be tracked by git. +The final thing I have done is to change the hooks directory in my local repo. With the default dir, .git/hooks, nothing can be tracked by git. -Instead I created a directory in the repo, ".githooks" and put my `post-commit` hook there. This way it can be tracked in the repo. +Instead I created a directory in the repo, .githooks and put my `post-commit` hook there. This way it can be tracked in the repo. -For git to know where the hooks are update the config +An update to the config is required so git knows where the hooks are ``` git config core.hooksPath .githooks ``` -*this option was introduced in got v2.9, so make sure you have that version or higher* +*Note: this option was introduced in got v2.9, so make sure you have that version or higher* -As far as I know there is no way to track hooks in a remote bare repo. If you know of a way I would be interested to hear about it. +As far as I am aware there is no way to track hooks in a remote bare repo. If you know of a way I would be interested to hear about it. -Who needs a convoluted CI/CD pipeline when a couple of one line scripts will do. Hopefully typing `:Gac` is easy enough for me to do that I will be able to keep my wiki up to date. +Who needs a convoluted CI/CD pipeline when a couple of one line scripts will do. Typing `:Gac` is easy enough that my wiki should now stay up to date.