From f9cbfe82f7fa0702ad2d0b51593f1ebe33e8db43 Mon Sep 17 00:00:00 2001 From: Michael Wayne Goodman Date: Sun, 10 Sep 2017 00:11:19 -0700 Subject: [PATCH] Add script for pre-commit git hook The script needs to be copied to .git/hooks/ in order to work. Resolves #50 --- CHANGELOG.md | 4 +++- Version.lsp | 2 +- utils/git-hooks/README.md | 19 +++++++++++++++ utils/git-hooks/pre-commit | 49 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 utils/git-hooks/README.md create mode 100755 utils/git-hooks/pre-commit diff --git a/CHANGELOG.md b/CHANGELOG.md index 117fad6..ea5a780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ Recent changes not yet part of a release are listed here: -* ... +* Add `utils/git-hooks/pre-commit` for auto-updating Version.lsp; Note + that it still needs to be copied locally to `.git/hooks/pre-commit` + in order to work ## [2017-09-08][] diff --git a/Version.lsp b/Version.lsp index a1a3a17..2def0c9 100644 --- a/Version.lsp +++ b/Version.lsp @@ -1,4 +1,4 @@ (in-package :lkb) -(defparameter *grammar-version* "Jacy (2017-09-08-develop)") +(defparameter *grammar-version* "Jacy-develop (2017-09-10 07:11:19+00:00)") diff --git a/utils/git-hooks/README.md b/utils/git-hooks/README.md new file mode 100644 index 0000000..1afddf1 --- /dev/null +++ b/utils/git-hooks/README.md @@ -0,0 +1,19 @@ +# Git Hooks + +This directory contains hooks for Git that developers are encouraged +to use when working on the grammar. + +To use the hooks, please copy them into your `.git/hooks` directory. +For example: + +``` +$ cp utils/git-hooks/pre-commit .git/hooks/pre-commit +``` + +## pre-commit + +The pre-commit hook checks for things before a commit happens. It can +be used, e.g., to check if a grammar compiles or passes regression +tests. The script here only checks if Version.lsp has been updated; +if not, it prompts the user to update it and commit, commit anyway, or +abort the commit entirely. diff --git a/utils/git-hooks/pre-commit b/utils/git-hooks/pre-commit new file mode 100755 index 0000000..832bedb --- /dev/null +++ b/utils/git-hooks/pre-commit @@ -0,0 +1,49 @@ +#!/bin/bash + +# If Version.lsp is not changed, prompt the user to use the current +# date and time as the version. + +# if branch is not master, add it to the version string +branch="-$( git rev-parse --abbrev-ref HEAD )" +if "$branch" = "-master"; then + branch='' +fi + +newver="Jacy$branch ($( date --utc --rfc-3339=seconds))" + +exitcode=0 # 0 is success; otherwise commit is cancelled + +if ! $( git diff --cached --name-only --diff-filter=AM | grep -q '^Version.lsp$' ); then + + echo "Version.lsp is unchanged. Do you wish to update the version string" + echo "to \"$newver\" ?" + echo " [y]es : update and commit" + echo " [n]o : don't update, commit anyway" + echo " [a]bort : don't commit" + + exec < /dev/tty # get keyboard input + while true; do + read -n 1 -p '(y|n|a) ' choice + echo "" + case "$choice" in + [yY]) + sed -i "s/^(defparameter \*grammar-version\*.*/(defparameter *grammar-version* \"$newver\")/" Version.lsp + git add Version.lsp + break + ;; + [nN]) + break + ;; + [aA]) + echo "Aborting commit" + exitcode=1 + break + ;; + *) + echo "Invalid option" + ;; + esac + done +fi + +exit "$exitcode"