Skip to content

Instantly share code, notes, and snippets.

@nschneid

nschneid/pre-commit

Created Apr 26, 2015
Embed
What would you like to do?
Prevent git commits that miss files included in a LaTeX project
#!/bin/bash
# Git pre-commit hook to look for untracked files mentioned in the LaTeX and BibTeX logs.
# Fail if any are found. Note that this is not foolproof, as included .tex files
# not generating any errors or warnings may not be mentioned in the log.
#
# Goes in file .git/hooks/pre-commit under the repository root.
#
# Nathan Schneider (nschneid@cs.cmu.edu), 2015-02-26
# Adapted from http://stackoverflow.com/a/10932301
#
. git-sh-setup # for 'die' cmd
git status --porcelain | while IFS= read -r line;
do
if [[ $line == \?\?* ]] ; then # if the file begins with ?? it's untracked by git
fname=${line:3}
if [[ `fgrep "/$fname" tmp/*.log` || `fgrep "$fname" tmp/*.blg` ]] ; then
die "Uncommited files left! $fname" # this will always terminate commit
# say "Uncommited files left!" # this will just print the warning
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment