Page 1 of 1

Flagging neglected git commits

PostPosted: Thu May 19, 2016 9:41 am
by personalnadir
I store all my coding projects in a Programming directory that I have Hazel run rules to achieve two things: sync changed files and to flag up neglected git repositories. I have an unfortunate habit of working and forgetting to commit anything. To deal with this, I've tried to use Hazel to flag up projects with forgotten about commits.

To start with I tag folders I'm interested in, then there is a three step process:
  1. Check tagged folders contain a repository, if not remove the tag
  2. Check tagged folders contain changes to the working directory, if so add tag and show notification
    Image
  3. Check tagged folders marked as containing uncommitted changes are clean, if so remove tag added in step 2

Most of the rules are just checking last matched and adding/removing tags appropriately. The core part of this process is the below script, which gets used in some modified way at each step.

Code: Select all
cd "$1"
# find location of git repository
gitloc=`find . -name .git -type d -prune`
# test for a result
if [ -z $gitloc ]; then
  exit 1
fi

parentdir="$(dirname "$gitloc")"
cd $parentdir
# check if clean
if git status | grep --quiet "working directory clean"; then
    exit 1
else
    exit 0
fi


The entire thing would no doubt benefit from removing the find calls or caching the result after it's been run once, but otherwise seems work as desired.

Re: Flagging neglected git commits

PostPosted: Fri May 20, 2016 11:36 am
by personalnadir
The above was a little too intensive, so I've added an extra step in which writes the result of the find command to a file. There's now an extra step which should run once for each tagged folder. The script for that step is:
Code: Select all
cd "$1"
rm .hazelgitloc
gitloc=$(find . -name .git -type d -prune)
if [ $gitloc ]; then
  dirname $gitloc > .hazelgitloc
fi


Testing for a clean working directory then becomes
Code: Select all
cd "$1"
cd $( <.hazelgitloc )

if git status | grep --quiet "working directory clean"; then
    exit 0
else
    exit 1
fi