Skip to content

Instantly share code, notes, and snippets.

@nschneid
Created April 26, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nschneid/fea16295e328e834f13b to your computer and use it in GitHub Desktop.
Save nschneid/fea16295e328e834f13b to your computer and use it in GitHub Desktop.
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