Created
April 26, 2015 14:19
-
-
Save nschneid/fea16295e328e834f13b to your computer and use it in GitHub Desktop.
Prevent git commits that miss files included in a LaTeX project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 ([email protected]), 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