Created
April 25, 2014 13:51
-
-
Save KamilSzot/11290301 to your computer and use it in GitHub Desktop.
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
$ cat .git/hooks/pre-commit | |
#!/bin/bash | |
root_dir=`git rev-parse --show-toplevel` | |
for new_file in `git status --porcelain | awk '/\?\?/ { print $2 }'`; | |
do | |
echo -n "$new_file ... (i)gnore, (s)kip, (a)dd [default] ? " | |
read add_or_ignore < /dev/tty | |
echo -en "\033[1A\033[2K" > /dev/tty | |
if [ "$add_or_ignore" == "i" ] | |
then | |
echo "$new_file ... ignored from now on (to undo remove it from "`git rev-parse --git-dir`/info/exclude")" | |
echo $new_file >> `git rev-parse --git-dir`/info/exclude | |
else | |
if [ "$add_or_ignore" == "s" ] | |
then | |
echo "$new_file ... skipped (you'll be asked on next commit again)" | |
else | |
echo "$new_file ... added to repo" | |
git add $root_dir/$new_file | |
fi | |
fi | |
done | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pre-commit hook that forces you to either add new files to repo or to locally ignored files.