parent
43842b9822
commit
25b71d5fd6
@ -1,8 +1,27 @@
|
||||
.post {
|
||||
#tags {
|
||||
display: flex;
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
|
||||
li {
|
||||
margin-right: 5px;
|
||||
background-color: black;
|
||||
padding: 0 5px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
p code {
|
||||
background-color: #1c1c1c;
|
||||
color: #a31515;
|
||||
}
|
||||
|
||||
.postdate {
|
||||
font-size: 10pt;
|
||||
}
|
||||
|
||||
.title {
|
||||
|
||||
font-size: 16pt;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
---
|
||||
title: "Git Tips - Global Pre-commit Hooks"
|
||||
date: 2020-01-01T21:00:39Z
|
||||
tags: [git, testing, bash]
|
||||
---
|
||||
|
||||
[Git hooks][1] are a feature of the Git VCS that allow you to fire off custom logic on the client side when you take
|
||||
actions in your repository. These are shell scripts in the `.git/hooks/` directory of your repository, but they can also
|
||||
exist at `~/.githooks/`.
|
||||
|
||||
Any hooks found in `~/.githooks/` are executed globally for the user of that shell, this makes it awesome for running a
|
||||
custom workflow that is consistent across your entire machine.
|
||||
|
||||
## Useful hooks
|
||||
|
||||
My favorite hook that I'm running these days is a `~/.githooks/pre-commit` hook that auto runs tests and lint commands
|
||||
if they're found.
|
||||
|
||||
|
||||
```sh
|
||||
{{<highlight bash "linenos=table">}}
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ -f "$PWD/makefile" ] && [ ! -z "$(cat $PWD/makefile | grep '^lint:')" ]; then
|
||||
echo "running make lint"
|
||||
make lint
|
||||
elif [ -f "$PWD/package.json" ] && [ ! -z "$(cat $PWD/package.json | grep "^\"lint\":")" ]; then
|
||||
echo "running npm run lint"
|
||||
npm run lint
|
||||
fi
|
||||
|
||||
if [ -f "$PWD/makefile" ] && [ ! -z "$(cat $PWD/makefile | grep '^test:')" ]; then
|
||||
echo "running make test"
|
||||
make test
|
||||
elif [ -f "$PWD/package.json" ] && [ ! -z "$(cat $PWD/package.json | grep "^\"test\":")" ]; then
|
||||
echo "running npm run test"
|
||||
npm run test
|
||||
fi
|
||||
{{</highlight>}}
|
||||
```
|
||||
|
||||
|
||||
If the test or lint command fails then the `git commit` command fails. If I absolutely need to commit something in spite
|
||||
of the lint/test results failing I can do `git commit --no-verify` to skip the `pre-commit` hook.
|
||||
|
||||
[1]: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks "Git hooks"
|
@ -1,7 +1,11 @@
|
||||
#!/bin/bash
|
||||
exec docker run -it --rm --name hugo \
|
||||
-p 1313:1313 \
|
||||
-v $PWD:/opt/workdir:Z \
|
||||
--privileged \
|
||||
-u ${UID}:${UID} \
|
||||
--entrypoint=/usr/local/bin/hugo hugo $@
|
||||
if [ -z "$(docker ps | grep hugo)" ]; then
|
||||
exec docker run -it --rm --name hugo \
|
||||
-p 1313:1313 \
|
||||
-v $PWD:/opt/workdir:Z \
|
||||
--privileged \
|
||||
-u ${UID}:${UID} \
|
||||
--entrypoint=/usr/local/bin/hugo hugo $@
|
||||
else
|
||||
exec docker exec -it hugo hugo $@
|
||||
fi
|
@ -0,0 +1,20 @@
|
||||
{{ define "main" }}
|
||||
<article class="post">
|
||||
<h1 class="title"><a href="{{ .Permalink }}">{{ .Title }}</a> {{ if .Draft }}(Draft){{ end }}</h1>
|
||||
<p class="meta">
|
||||
<span class="postdate">Posted {{ .Date.Format "January 02 2006" }}</span><br/>
|
||||
{{ $taxo := "tags" }} <!-- Use the plural form here -->
|
||||
<ul id="{{ $taxo }}" >
|
||||
{{ range .Param $taxo }}
|
||||
{{ $name := . }}
|
||||
{{ with $.Site.GetPage (printf "/%s/%s" $taxo ($name | urlize)) }}
|
||||
<li><a href="{{ .Permalink }}">{{ $name }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<div class="post-content">{{ .Content | safeHTML }}</div>
|
||||
|
||||
</article>
|
||||
{{ end }}
|
Loading…
Reference in new issue