From dc986853e1be821e085b6ac9f40a61db1010b4a8 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 24 May 2016 17:02:33 +0200 Subject: [PATCH] feat(git): Update old tag refs in README.md using pre-commit hook --- .hooks/pre-commit | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 .hooks/pre-commit diff --git a/.hooks/pre-commit b/.hooks/pre-commit new file mode 100755 index 00000000..ca535bc6 --- /dev/null +++ b/.hooks/pre-commit @@ -0,0 +1,27 @@ +#!/bin/sh + +# Pass if the README.md isn't staged for commit +test "$(git diff --staged README.md)" || exit 0 + +# Redirect all output to stderr +exec 1>&2 + +# shellcheck disable=SC2016 +tag_prev=$(git tag -l | tail -2 | head -1) +tag_curr=$(git tag -l | tail -1) + +# Pass if tags aren't defined +[ "$tag_prev" ] || exit 0 +[ "$tag_curr" ] || exit 0 + +sed -n "/${tag_prev}/q1" README.md + +# Pass if the previous tag wasn't found +[ $? -eq 1 ] || exit 0 + +echo +echo "\033[36;1mNOTICE \033[37;1m**\033[0m Updating README.md with latest tag (\033[1m${tag_prev}\033[0m => \033[1m${tag_curr}\033[0m)" +echo " The change will be staged for commit..." +echo + +sed -i "s/${tag_prev}/${tag_curr}/g" README.md