Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions src/cargo/ops/cargo_package/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,28 +274,9 @@ fn dirty_files_outside_pkg_root(
dirty_files.insert(workdir.join(rel_path));
}
Err(e) => {
if e.code() == git2::ErrorCode::NotFound {
// Object not found means this file might be inside a subrepo/submodule.
// Let's check its status from that repo.
let abs_path = workdir.join(&rel_path);
if let Ok(repo) = git2::Repository::discover(&abs_path) {
let is_dirty = if repo.workdir() == Some(workdir) {
false
} else if let Ok(path) =
paths::strip_prefix_canonical(&abs_path, repo.workdir().unwrap())
{
repo.status_file(&path) != Ok(git2::Status::CURRENT)
} else {
false
};
if is_dirty {
dirty_files.insert(abs_path);
}
}
}

// Dirtiness check for symlinks is mostly informational.
// To avoid adding more complicated logic,
// And changes in submodule would fail git-status as well (see #15384).
// To avoid adding complicated logic to handle that,
// for now we ignore the status check failure.
debug!(
"failed to get status from file `{}` in git repo at `{}`: {e}",
Expand Down
9 changes: 3 additions & 6 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,16 +1463,13 @@ fn dirty_file_outside_pkg_root_inside_submodule() {
p.symlink("submodule/file.txt", "isengard/src/file.txt");
git::add(&repo);
git::commit(&repo);
// This dirtyness should be detected in the future.
p.change_file("submodule/file.txt", "changed");

p.cargo("package --workspace --no-verify")
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] 1 files in the working directory contain changes that were not yet committed into git:

submodule/file.txt

to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard)
[PACKAGED] 6 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)

"#]])
.run();
Expand Down