install.fairie/home/.chezmoiscripts_disabled/disabled/run_onchange_after_08-git-hooks.tmpl
2024-02-27 09:21:12 +00:00

38 lines
1.6 KiB
Cheetah

{{- if false -}}
#!/usr/bin/env bash
### This script is `if false` blocked out! ###
# This script is disabled until we figure out sensible git hooks for linters / auto-fixers
# that are not too aggressive. Megabyte Labs projects can install git hooks by running
# `bash start.sh`.
#
# To re-enable, add the missing files to the ~/.config/git/template folder, uncomment the templatedir line
# in ~/.config/git/config, and uncomment the Husky script in .chezmoiexternal.toml. Then, move this file to
# the universal folder.
{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}
{{ $gitHooks := (output "find" (joinPath .chezmoi.homeDir ".local" "share" "shared-common" "common" ".config" "husky") "-mindepth" "1" "-maxdepth" "1" "-type" "f") -}}
{{- range $gitHook := splitList "\n" $gitHooks -}}
{{- if ne $gitHook "" -}}
# {{ $gitHook }} hash: {{ include $gitHook | sha256sum }}
{{- end -}}
{{- end }}
### Ensure git hooks directory exists
logg info 'Ensuring git hooks directory exists'
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/git/template/hooks"
### Ensure git hooks are executable
logg info 'Ensuring git hooks are up-to-date'
find "${XDG_DATA_HOME:-$HOME/.local/share}/shared-common/common/.config/husky" -mindepth 1 -maxdepth 1 -type f | while read HOOK; do
cp "$HOOK" "${XDG_CONFIG_HOME:-$HOME/.config}/git/template/hooks"
done
### Make git hooks executable
if [ -d "${XDG_CONFIG_HOME:-$HOME/.config}/git/template/hooks" ]; then
logg info 'Ensuring git hooks are executable'
chmod +x "${XDG_CONFIG_HOME:-$HOME/.config}/git/template/hooks/"*
fi
{{ end -}}