From db51de25a2dcac3850dc5862d215049378d7277b Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 30 Jun 2016 00:13:59 +1200 Subject: Extend jfc(1) to check for changes before commit --- bin/jfc | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'bin/jfc') diff --git a/bin/jfc b/bin/jfc index cb032a5c..1068280a 100755 --- a/bin/jfc +++ b/bin/jfc @@ -1,7 +1,24 @@ -#!/bin/sh +#!/usr/bin/env bash # jfc(1) -- Just add everything to a Git repository and quietly commit with a # stock message -git add --all -git commit --message 'Committed by jfc(1)' --quiet +# Check we have what we need +hash git || exit + +# Detect changes +if ! git diff-index --quiet HEAD ; then + changed=1 +fi + +# Detect untracked files +while read -d '' -r ; do + untracked=1 + break +done < <(git ls-files -z --others --exclude-standard) + +# If either applies, add and commit +if ((changed || untracked)) ; then + git add --all || exit + git commit --message 'Committed by jfc(1)' --quiet || exit +fi -- cgit v1.2.3