From 21d86f1a2e3f3e811a67903a6b61d223673f75a3 Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Sun, 8 Sep 2024 11:31:16 -0500 Subject: [PATCH] Add git hooks --- git/hooks/pre-commit.sh | 14 ++++++++++++++ git/setup.pl | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 git/hooks/pre-commit.sh create mode 100755 git/setup.pl diff --git a/git/hooks/pre-commit.sh b/git/hooks/pre-commit.sh new file mode 100755 index 0000000..c8b5eb4 --- /dev/null +++ b/git/hooks/pre-commit.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +status=0 + +PRECIOUS=$(which precious) +if [[ -z $PRECIOUS ]]; then + PRECIOUS=./bin/precious +fi + +if ! "$PRECIOUS" lint -s; then + status=$((status + 1)) +fi + +exit $status diff --git a/git/setup.pl b/git/setup.pl new file mode 100755 index 0000000..8c99cb8 --- /dev/null +++ b/git/setup.pl @@ -0,0 +1,27 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Cwd qw( abs_path ); + +symlink_hook('pre-commit'); + +sub symlink_hook { + my $hook = shift; + + my $dot = ".git/hooks/$hook"; + my $file = "git/hooks/$hook.sh"; + my $link = "../../$file"; + + if ( -e $dot ) { + if ( -l $dot ) { + return if readlink $dot eq $link; + } + warn "You already have a hook at $dot!\n"; + return; + } + + symlink $link, $dot + or die "Could not link $dot => $link: $!"; +}