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

cargo publish and cargo package incorrectly complain about .gitignored Cargo.lock in library #7319

Closed
felixc opened this issue Sep 2, 2019 · 6 comments · Fixed by #7448
Closed
Labels
A-lockfile Area: Cargo.lock issues C-bug Category: bug Command-publish

Comments

@felixc
Copy link
Contributor

felixc commented Sep 2, 2019

Recently (at some point since mid-July; but I don't know the exact version when it started) in my two library repos Cargo has started failing when attempting to cargo publish, with the error:

$ cargo publish
    Updating crates.io index
error: 1 files in the working directory contain changes that were not yet committed into git:

Cargo.lock

to proceed despite this, pass the `--allow-dirty` flag

However, this is incorrect because:

  1. This is a library, so Cargo.lock should not be committed or published.
  2. Cargo.lock is in .gitignore.
  3. Cargo.lock has never been checked in to Git.

For confirmation:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

$ git log Cargo.lock
[no output]

$ git rm --cached Cargo.lock
fatal: pathspec 'Cargo.lock' did not match any files        

$ cat .gitignore
Cargo.lock
target/

cargo publish fails in the same way/with the same error.

As a workaround, deleting Cargo.lock entirely allows publishing (and of course since it's a library it can just be safely recreated afterwards).

The two repositories where I have observed this happening are https://github.com/felixc/rexiv2 and https://github.com/felixc/gexiv2-sys. I tried to reproduce it by creating a minimal empty repo but was not immediately able to, so I'm not sure what part of the repo configuration is leading to this. Some discussion on Discord suggested it might have to do with the runnable examples/ targets leading to some mis-detection as a binary crate rather than a library one?

Notes

$ cargo version
cargo 1.37.0 (9edd08916 2019-08-02)

$ rustup --version
rustup 1.18.3 (435397f48 2019-05-22)

$ rustup toolchain list
stable-x86_64-unknown-linux-gnu (default)
beta-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu
1.20.0-x86_64-unknown-linux-gnu

$ uname -a
Linux mir 4.19.0-5-amd64 #1 SMP Debian 4.19.37-5+deb10u2 (2019-08-08) x86_64 GNU/Linux
@felixc felixc added the C-bug Category: bug label Sep 2, 2019
@felixc
Copy link
Contributor Author

felixc commented Sep 2, 2019

CC @Eh2406 since you suggested on Discord that I should file this as you had some ideas about which parts of the relevant code might have changed recently.

@Eh2406
Copy link
Contributor

Eh2406 commented Sep 2, 2019

Thanks, yes I would guess that it is something to do with #7026. CC @ehuss as this may have to do with your lockfile on publish work.

@nickbabcock
Copy link

I have this same issue with my repo: boxcars. This was a bug introduced in Cargo 1.37.0. I've downgraded to Cargo 1.36.0 successfully. Deleting a .gitignored Cargo.lock before pushing a library seems too inconvenient of a workaround.

@elichai
Copy link

elichai commented Nov 27, 2019

This bug still exist in cargo 1.39.0 (1c6ec66d5 2019-09-30)

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
$ bat .gitignore 
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: .gitignore
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ /target
   2   │ **/*.rs.bk
   3   │ Cargo.lock
   4   │ .idea
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
$ cargo publish
    Updating crates.io index
error: 1 files in the working directory contain changes that were not yet committed into git:

Cargo.lock

to proceed despite this and include the uncommited changes, pass the `--allow-dirty` flag
$ bat Cargo.toml 
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: Cargo.toml
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ [package]
   2   │ name = "log-derive"
   3   │ version = "0.3.2"
   4   │ license = "MIT/Apache-2.0"
   5   │ authors = ["Elichai <[email protected]>"]
   6   │ repository = "https://github.com/elichai/log-derive"
   7   │ readme = "README.md"
   8   │ edition = "2018"
   9   │ description = "Procedural Macros for logging the result and inputs of a function"
  10   │ categories = ["development-tools::debugging"]
  11   │ keywords = ["log", "macro", "derive", "logging", "function"]
  12   │ include = [
  13   │     "src/*.rs",
  14   │     "Cargo.toml",
  15   │ ]
  16   │ 
  17   │ [dependencies]
  18   │ darling = "0.10.0"
  19   │ proc-macro2 = "1.0.3"
  20   │ #syn = { version = "0.15", features = ["full", "extra-traits"] } # -> For development
  21   │ syn = { version = "1.0.5", features = ["full"] }
  22   │ quote = "1.0.2"
  23   │ log = "0.4"
  24   │ 
  25   │ [dev-dependencies]
  26   │ simplelog = "0.7"
  27   │ 
  28   │ [badges]
  29   │ travis-ci = { repository = "elichai/log-derive" }
  30   │ 
  31   │ [lib]
  32   │ proc-macro = true

@ehuss
Copy link
Contributor

ehuss commented Dec 3, 2019

@elichai the fix is in 1.40, can you try that?

@elichai
Copy link

elichai commented Dec 4, 2019

@elichai the fix is in 1.40, can you try that?

Yep, fixed. sorry :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lockfile Area: Cargo.lock issues C-bug Category: bug Command-publish
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants