Conversation
|
Actually forgot |
|
I'm sorry for long delay since I focused on a few projects (and some private projects). Let me check this. |
build.rs
Outdated
|
|
||
| set -e | ||
|
|
||
| git stash --keep-index --include-untracked --quiet |
There was a problem hiding this comment.
I have two points here.
- I agree with pre-commit hook runs on local files, not on commited ones #3, however,
--include-untrackedwould take time when there is a heavy directory such asnode_modules. What is the case untracked file should be stashed? - I think showing what hook script does is preferred rather than doing it implicitly. It is important when these lines don't work as we intended. We can analyze what did not work. I prefer to adding
echoto show what is being done.
echo '+git stash --keep-index --include-untracked'
git stash --keep-index --include-untrackedThere was a problem hiding this comment.
Will do, should the trap echo too?
There was a problem hiding this comment.
Everything should echo now. Also removed the --quiet
build.rs
Outdated
| set -e | ||
|
|
||
| git stash --keep-index --include-untracked --quiet | ||
| trap "git reset --quiet --hard HEAD && git stash pop --index --quiet" EXIT INT TERM |
There was a problem hiding this comment.
I think this git stash pop will fail when the script generates some untracked file. For example, let's say cargo test generate output.txt. If output.txt already exists, git stash push saves the output.txt, then cargo test will be run for check which generates new output.txt. Finally git stash pop tries to restore output.txt but it already exists. I think we should clean untracked files before git stash pop.
There was a problem hiding this comment.
I'll respond to the second point above here, since it's the same answer.
The reset --hard is needed to avoid pop conflicts. Since the hard reset would literally wipe the repo we need --include-untracked to save all the files. We would lose all files generated by the hook, true, but I'm not sure this is avoidable
There was a problem hiding this comment.
Since the hard reset would literally wipe the repo we need
I think git reset --hard does not wipe untracked files. Please try the following in some Git repository
# Generate a file
echo hello > hello.txt
# Check hello.txt is untracked
git status
# Run hard reset
git reset --hard HEAD
# hello.txt would still existThere was a problem hiding this comment.
Damn, my git-fu is failing me! Removed the reset and the --include-untracked. Not sure how to handle the cargo commands generating files.
Runs
git stashbefore any hook operation and trapsstash popfor whenever the hook exits. Fixes #3.