views:

46

answers:

1

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.

+1  A: 

No, git stash will only "record the current state of the working directory and the index". So stashing won't pickup your untracked files.

Switching to a temporary branch and tracking the untracked files there, as you suggest, seems like a reasonable approach.

David Underhill
I suppose my definition of "working directory" differs from that of the git developers.I've solved my problem by using git-checkout-index to a temporary directory and building there. I'd still rather use git-stash if possible, however.
MidoriKid