Skip to content

Instantly share code, notes, and snippets.

@forivall
Created July 15, 2013 20:31
Show Gist options
  • Save forivall/6003165 to your computer and use it in GitHub Desktop.
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)
# 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
@forivall
Copy link
Author

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 do git 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 no procfs for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment