A related question How do you stash an untracked file? was answered with "track the file." This doesn't work for my particular needs, however.
I'm trying to stash everything that isn't in the index with git stash save --keep-index
so that I can validate the index in my pre-commit hook. The idea is from the "Testing partial commits" example of the git-stash man page. I want to make sure that what I'm actually committing passes the tests and not just whats in the working directory. Here's what I have so far:
echo "Running tests on the staging area."
git stash save --keep-index
# configure, build, run tests, clean
git stash pop; true
This seems to work until I have untracked files in my working directory which don't get stashed. Some searching resulted in a feature request from two years ago: Option to save untracked and/or ignored files in stash, but nothing else.
Should I be using stash at all? Perhaps theres a better way involving temporary branches or something.