3 ms·
Think about the `git stash` use case. The goal is to go from a messy, WIP state that may or may not compile, back to a more stable, probably-working state repre
by Rusky 6y ago
Think about the `git stash` use case. The goal is to go from a messy, WIP state that may or may not compile, back to a more stable, probably-working state represented by a commit.
That messy state may include a new, partially-implemented module file. By default `git stash` will leave it alone, because it's untracked. But `git stash` will also remove its corresponding `mod` declaration, and any uses of it, all at once.
Now say you want to build and run. If that WIP module file gets picked up automatically, it will probably break the build! It may simply be incomplete, or it may depend on some of those stashed changes, or whatever else. Even if it happens to typecheck, now you're assuming that it's all dead code- but it may have some public API (including trait impls!), and still be included in the build!
In fact, we already have a taste of this kind of problem, ever since Cargo started running build.rs scripts automatically, even without a `package.build` key in `Cargo.toml`. If you add a build script with some build-dependencies, run `git stash`, and then build, the build script will fail to compile!
Perhaps you could argue that this is a deficiency in `git stash` that Rust shouldn't have to be concerned with. But if `git stash` removed untracked files as well, that would simply break other use cases instead! For example, I often have a few extra files laying around, which I don't ever intend to commit or .gitignore- sample inputs or outputs, short-term todo lists, or other scratch-pad-like data. Ideally `git stash` would leave those alone- but it's hard for git to tell those apart from the problematic cases above.
- riffraff 6y agoFWIW, if you have a new file in WIP state and have changes related to it that you want to stash it might be better to `git add` it so that it gets stashed/unstashed together with the other related changes.
- nicoburns 6y agoIf you run git stash with the -u option (`git stash -u`), then it will also stash untracked files. IMO leaving uncommitted/unignored files around is asking for trouble. It's far too easy to accidentally delete or commit them. Why not have a prefix that you use for these files, and use a wildcard gitignore?
- Rusky 6y agoI'm perfectly aware of `git stash -u` ("by default") as well as `git add -N`, etc, but as I also very intentionally pointed out, that has its own downsides. That is, my own personal workflow poses essentially zero risk of deleting or committing those files, so "quit using the file system the way I've always used it" is no less of a stumbling block for me than "maintain `mod` declarations" is for you. We simply haven't found an approach that doesn't step on someone's toes, so the one that Rust was already using from the 2015 edition stuck.
- nicoburns 6y agoHmm... would you object to `use` automatically linking in modules without a `mod` declaration? It seems that that would work in the situations with regard to stashing (a git stash that stashed `mod` statements would also stash `use` statements).