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 package --allow-dirty fails for not recognizing deleted un-staged files in git repo #9580

Closed
xdngcs opened this issue Jun 13, 2021 · 0 comments · Fixed by #9645
Closed
Labels
A-git Area: anything dealing with git C-bug Category: bug Command-package

Comments

@xdngcs
Copy link

xdngcs commented Jun 13, 2021

Problem

My workflow has a command alias that includes build, test and packaging steps in one run. During recent work, a weird issue was discovered that a file deletion would cause such workflow to fail. It was later found cargo package --allow-drity would fail for No such file or directory (os error 2) when deleted file is not yet staged in the git repo, and cargo package would still show the file deleted in the list. The issue would be fixed by a git add . command to stage all local changes (no commit needed).

Expecting the deleted files would not fail a cargo package --allow-dirty run, for better and faster local change testing on every workflow steps, and not getting developers running into weird issue when forgetting file staging

Steps

  1. Start a new project with git: cargo new --vcs git --bin cargo-git-test
  2. Test the project with everything default, all following commands should return as expected:
    • cargo run: success
    • git status: all files untracked/unstaged
    • cargo package: fail for files not committed (expected behavior)
    • cargo package --allow-dirty: success and all files recognized
  3. Work on the project to add more files, for example:
// create lib.rs
pub fn hello_world() {
    println!("Hello World");
}

// change main.rs
use cargo_git_test::hello_world;

fn main() {
    hello_world();
}
  1. Create first git commit git add . && git commit -m "first commit". Expect no behavior change after the first commit (despite cargo package would not complain about uncommitted changes)
  2. Delete lib.rs and make main.rs buildable:
// main.rs
// Remove dependency on lib.rs
fn main() {
    println!("Hello World, but...");
}
  1. Run cargo commands with current project status:
    • cargo run: success, output should indicate the updated print string
    • cargo package: fail as expected, but still referring to the deleted file
warning: manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
error: 2 files in the working directory contain changes that were not yet committed into git:

src/lib.rs
src/main.rs

to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
  • cargo package --allow-dirty: fail with No such file or directory (os error 2)
warning: manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
   Packaging cargo-git-test v0.1.0 (/home/user/cargo-git-test)
error: failed to prepare local package for uploading

Caused by:
  failed to open for archiving: `/home/user/cargo-git-test/src/lib.rs`

Caused by:
  No such file or directory (os error 2)
  1. Stage all files by git add . (no commit needed), and cargo package --allow-dirty would pass, with cargo package no longer show the deleted file in list.

Possible Solution(s)

It seems like cargo package command would hold a stale list of files when git repository is not staged. It would refer to the real file content so when all files still exist it would not have issue. But when files are deleted, it would fail by trying to refer them in the stale list. It is possible to fix this by treating deleted files specially or ignoring unfound files (but also would need to fail in case of unanticipated file system change to prevent an FP packaging success......)

Notes

Output of cargo version: cargo 1.52.0 (69767412a 2021-04-21)

Have tested the issue on different Linux distributions and it appears the same. The reproducing steps was performed in following environment after fresh installation:

  • Ubuntu 21.04
  • git version 2.30.2
  • rustup 1.24.3 (ce5817a94 2021-05-31)
@xdngcs xdngcs added the C-bug Category: bug label Jun 13, 2021
@ehuss ehuss added A-git Area: anything dealing with git Command-package labels Jul 2, 2021
@bors bors closed this as completed in b747054 Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-git Area: anything dealing with git C-bug Category: bug Command-package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants