-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
instead of writing a .gitignore
with /target
-- output a .gitignore
with *
*inside* target/
#11548
Comments
This looks pretty interesting! Thanks for your proposal. There are several things needs to consider. One is backward compatibility. I believe it is rare that a user commits stuff under Cargo supports various kinds of VCS, e.g. Git, Mecurial, Pijul, and Fossil. We don't need to do it all at once, as 99% of Rust projects choose Git. Still, we can perform more researches on how other VCS works. Going further, “which VCS ignore file should be generated” becomes a question. Is it a good practice for Cargo to check VCS information for each run of The idea is cool anyway. Thank you again. |
Writing 4 tiny (single line) files should not be a significant cost compared to any kind of average cargo compile, even hello world. Meson for example generates ones for git and mercurial only, but others wouldn't be difficult, assuming they provide glob support. However, it only generates them once. Cargo could do the same if |
Please keep |
In what case would you need target to be a symlink? |
I keep my build artifacts on a separate partition to keep my main one from croaking when it gets too full. It also makes it easy to keep them out of backups by just ignoring where all build artifacts live. |
Can't the target directory be controlled via a config option or environment variable? Alternatively, a bind mount is also possible. I don't know how the cargo team sees it, but this seems like a fairly niche use case, it feels like the usability improvement would be greater in the general case. Besides, you can still have an additional .gitignore file in the project directory itself, it just wouldn't be there by default (just as target as a symlink isn't there by default, so I think this could be easily added to whatever setup script you may have) |
Can it include variables? Say,
I don't think involving
That doesn't help with projects I contribute to (I've made quite a few PRs removing the trailing slash in projects' |
@mathstuf you can add For the other VCS, we could either take the same approach (if possible) or simply keep the current approach. Because the It could be interesting to check if other VCS support this approach. At least judging from mercurial's documentation, it doesn't support it. So we'd have to keep the code paths of the "old" approach around either way.
This shouldn't be a problem. Git keeps tracking already tracked files, even if they are matched by a gitignore file. It is also possible to track new files that are ignored with I think this is a nice cleanup for simple Rust projects with basically no downsides. |
IMO, it doesn't belong there. Global ignores are for things I do (e.g., |
Well, you are the one creating the symlink, right? You can also put it in It's not cargo's responsibility to advertise the preferred setup of some people with a very niche use case, especially if that use case can easily be achieved in multiple different ways. |
Hmm. Perhaps if there were a way to exclude it if it is a symlink (like trailing- |
if [ -d .git ] && [ -L target ] && ! grep -q "/target" .git/info/exclude
then
echo "/target" >> .git/info/exclude
fi Run that as a shell hook whenever you cd into a new directory. |
Writing a For example, one could There might be some other tools in the wild only understanding the root |
That's a good point. I agree that we should keep the template for a (long) while because of that. People can still "opt-in" early by removing the
I'd say a tool like that is just fundamentally broken, because it doesn't match git's behavior. Users of these tools would also have problems with other existing tools that use this technique (e.g. virtualenv). |
Just a note that this hook is not sufficient, namely in that it fails to consider worktrees, and that it waits until coming back to a directory to update the set. In any case a hook on |
I created a new issue (#15061) that only deals with adding the new file to the target directory. |
Problem
currently
cargo init
helpfully writes out a.gitignore
with the following contents:/target
this ~generally means that any rust project now needs to have this
/target
entry in.gitignore
instead of needing this in
.gitignore
, one can create a self-ignoring directory by writing a.gitignore
with the contents*
inside of it. this is (for example) whatvirtualenv
does:this would remove the need for everyone having
/target
in theirgitignore
and instead have it be automatic!Proposed Solution
the proposal is to create a
.gitignore
with*
in thetarget
directory upon creation and phase out the top-level.gitignore
's/target
entryNotes
No response
The text was updated successfully, but these errors were encountered: