Created
July 15, 2013 20:31
-
-
Save forivall/6003165 to your computer and use it in GitHub Desktop.
Don't allow git --all when files are currently staged. ~ An interesting lesson in git's use of environment vars (GIT_INDEX_FILE)
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
# don't allow --all when we have staged files. It's usually a mistake | |
# depends on procfs and won't work through gitaliases | |
while read -d $'\0' arg ; do | |
if [[ "$arg" == -a* || "$arg" == -[b-zB-Z]*a* || "$arg" == '--all' ]] ; then | |
if (( $((unset GIT_INDEX_FILE; git diff --cached --name-only)|wc -l) > 0 )) ; then | |
echo 'using --all while files are cached. don'\''t do that.' | |
exit 1 | |
fi | |
fi | |
done < /proc/$PPID/cmdline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome, glad to hear when my random bits get extra life. I've completely forgotten about the
--all
option for git commit, and i just always dogit add -u
as a separate stage these days. Also, i've been working on macos most of the time (though looking to switch back to linux), so noprocfs
for me!