Skip to content
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

Document default values of package.include and package.exclude of Cargo.toml #9502

Closed
malaire opened this issue May 19, 2021 · 7 comments · Fixed by #9538
Closed

Document default values of package.include and package.exclude of Cargo.toml #9502

malaire opened this issue May 19, 2021 · 7 comments · Fixed by #9538
Labels
A-documenting-cargo-itself Area: Cargo's documentation C-bug Category: bug

Comments

@malaire
Copy link

malaire commented May 19, 2021

Default values of package.include and package.exclude doesn't seem to be documented anywhere, so it can be a surprise what files cargo publish actually includes in the crate.

This is especially bad since cargo publish is irreversible.

@malaire malaire added the C-bug Category: bug label May 19, 2021
@weihanglo
Copy link
Member

AFAIK there is no default value for package.include and package.exclude add a .* rule under some circumstances. There is a document about cargo package respecting gitignore but it's not very detailed. Maybe we can add more information into the manifest chapter instead.

Also, if you're in trouble with cargo publish inclusion rules, providing a reproducible example would help a lot 😀

@malaire
Copy link
Author

malaire commented May 19, 2021

So by default cargo publish includes everything not ignored by version control system?

@weihanglo
Copy link
Member

I think so. At least for a package under git-control and without package.include.

@malaire
Copy link
Author

malaire commented May 20, 2021

Documentation is contradictory about that:

https://doc.rust-lang.org/cargo/reference/publishing.html#packaging-a-crate

Cargo will automatically ignore files ignored by your version control system when packaging

That implies that both .gitignore and .git/info/exclude are used.

https://doc.rust-lang.org/cargo/reference/manifest.html#the-exclude-and-include-fields

If git is being used for a package, the exclude field will be seeded with the gitignore settings from the repository.

That says that only .gitignore is used and .git/info/exclude is not used.

So is .git/info/exclude used or not?

@weihanglo
Copy link
Member

weihanglo commented May 20, 2021

First time knows .git/info/exclud. Cool stuff!

After some quick testing, I found that, unfortunately, cargo publish only support .gitignore, which means it is not fully git-compliance nor supporting other VCS. One solution is to make the doc aligns to the current implementation, but for now let's wait for cargo team's opinion.

Edit: actually it works and supports git. I typed something wrong in the past.

@ehuss
Copy link
Contributor

ehuss commented Jun 3, 2021

I opened PR #9538 to add documentation for this, please let me know if you have any feedback.

After some quick testing, I found that, unfortunately, cargo publish only support .gitignore, which means it is not fully git-compliance nor supporting other VCS.

This should be working, can you put together an example where it doesn't? Did you maybe not have any commits? Or have an include rule? The following works for me:

cargo new foo
cd foo
git add .gitignore Cargo.toml src
git commit -m test
touch bar
cargo package --list --allow-dirty  # Should contain `bar`
echo bar >> .git/info/exclude
cargo package --list --allow-dirty  # Should not contain `bar`

@weihanglo
Copy link
Member

It works for me now. I guess I made some mistake days ago. 😞

Sorry about that and thank for your patch PR!

@bors bors closed this as completed in 4ab971b Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documenting-cargo-itself Area: Cargo's documentation C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants