Skip to content

Commit

Permalink
Add git hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed Sep 8, 2024
1 parent ddbef7b commit cf129b1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
14 changes: 14 additions & 0 deletions git/hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

Check failure on line 1 in git/hooks/pre-commit.sh

View workflow job for this annotation

GitHub Actions / Check that code is lint clean using precious

Linting with shellcheck failed

status=0

PRECIOUS=$(which precious)
if [[ -z $PRECIOUS ]]; then
PRECIOUS=./bin/precious
fi

if !"$PRECIOUS" lint -s; then
status=$((status + 1))
fi

exit $status
27 changes: 27 additions & 0 deletions git/setup.pl
Original file line number Diff line number Diff line change
@@ -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: $!";
}

0 comments on commit cf129b1

Please sign in to comment.