-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix(package): report lockfile / workspace manifest is dirty #15276
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
Changes from all commits
af1e77c
4244b64
2375b19
1b94e1b
d9908b1
f0907fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
use std::fs::{self, read_to_string, File}; | ||
use std::path::Path; | ||
|
||
use cargo_test_support::compare::assert_e2e; | ||
use cargo_test_support::prelude::*; | ||
use cargo_test_support::publish::validate_crate_contents; | ||
use cargo_test_support::registry::{self, Package}; | ||
|
@@ -1212,15 +1213,6 @@ fn vcs_status_check_for_each_workspace_member() { | |
}); | ||
git::commit(&repo); | ||
|
||
p.change_file( | ||
"Cargo.toml", | ||
r#" | ||
[workspace] | ||
members = ["isengard", "mordor"] | ||
[workspace.package] | ||
edition = "2021" | ||
"#, | ||
); | ||
// Dirty file outside won't affect packaging. | ||
p.change_file("hobbit", "changed!"); | ||
p.change_file("mordor/src/lib.rs", "changed!"); | ||
|
@@ -1357,7 +1349,8 @@ fn dirty_file_outside_pkg_root_considered_dirty() { | |
p.change_file("original-dir/file", "after"); | ||
// * Changes in files outside pkg root that `license-file`/`readme` point to | ||
p.change_file("LICENSE", "after"); | ||
// * When workspace inheritance is involved and changed | ||
// * When workspace root manifest has changned, | ||
// no matter whether workspace inheritance is involved. | ||
p.change_file( | ||
"Cargo.toml", | ||
r#" | ||
|
@@ -1378,8 +1371,9 @@ fn dirty_file_outside_pkg_root_considered_dirty() { | |
p.cargo("package --workspace --no-verify") | ||
.with_status(101) | ||
.with_stderr_data(str![[r#" | ||
[ERROR] 4 files in the working directory contain changes that were not yet committed into git: | ||
[ERROR] 5 files in the working directory contain changes that were not yet committed into git: | ||
|
||
Cargo.toml | ||
LICENSE | ||
README.md | ||
lib.rs | ||
|
@@ -1432,6 +1426,133 @@ edition = "2021" | |
); | ||
} | ||
|
||
#[cargo_test] | ||
fn dirty_ws_lockfile_dirty() { | ||
let (p, repo) = git::new_repo("foo", |p| { | ||
p.file( | ||
"Cargo.toml", | ||
r#" | ||
[workspace] | ||
members = ["isengard"] | ||
resolver = "2" | ||
[workspace.package] | ||
edition = "2015" | ||
"#, | ||
) | ||
.file( | ||
"isengard/Cargo.toml", | ||
r#" | ||
[package] | ||
name = "isengard" | ||
edition.workspace = true | ||
homepage = "saruman" | ||
description = "saruman" | ||
license = "MIT" | ||
"#, | ||
) | ||
.file("isengard/src/lib.rs", "") | ||
}); | ||
git::commit(&repo); | ||
|
||
p.cargo("package --workspace --no-verify") | ||
.with_stderr_data(str![[r#" | ||
[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard) | ||
[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) | ||
|
||
"#]]) | ||
.run(); | ||
|
||
// lockfile is untracked. | ||
p.cargo("generate-lockfile").run(); | ||
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: | ||
|
||
Cargo.lock | ||
|
||
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag | ||
|
||
"#]]) | ||
.run(); | ||
|
||
// lockfile is tracked. | ||
p.cargo("clean").run(); | ||
git::add(&repo); | ||
git::commit(&repo); | ||
p.cargo("package --workspace --no-verify") | ||
.with_stderr_data(str![[r#" | ||
[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard) | ||
[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) | ||
|
||
"#]]) | ||
.run(); | ||
|
||
// Simulate that Cargo.lock had some outdated but SemVer compat dependency changes. | ||
Package::new("dep", "1.0.0").publish(); | ||
Package::new("dep", "1.1.0").publish(); | ||
p.cargo("clean").run(); | ||
p.cargo("add dep@1").run(); | ||
git::add(&repo); | ||
git::commit(&repo); | ||
// make sure we have dep@1.1.0 in lockfile | ||
assert_e2e().eq( | ||
&p.read_lockfile(), | ||
str![[r##" | ||
# This file is automatically @generated by Cargo. | ||
# It is not intended for manual editing. | ||
version = 4 | ||
|
||
[[package]] | ||
name = "dep" | ||
version = "1.1.0" | ||
source = "registry+https://github.com/rust-lang/crates.io-index" | ||
checksum = "77d3d6a4f2203d590707cc803c94afbe36393bbdba757ef66986f39159eaab51" | ||
|
||
[[package]] | ||
name = "isengard" | ||
version = "0.0.0" | ||
dependencies = [ | ||
"dep", | ||
] | ||
|
||
"##]], | ||
); | ||
p.cargo("update dep --precise 1.0.0") | ||
.with_stderr_data(str![[r#" | ||
[UPDATING] `dummy-registry` index | ||
[DOWNGRADING] dep v1.1.0 -> v1.0.0 | ||
|
||
"#]]) | ||
.run(); | ||
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: | ||
|
||
Cargo.lock | ||
|
||
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag | ||
|
||
"#]]) | ||
.run(); | ||
|
||
// Now check if it is considered dirty when removed. | ||
p.cargo("clean").run(); | ||
fs::remove_file(p.root().join("Cargo.lock")).unwrap(); | ||
p.cargo("package --workspace --no-verify") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be some path normalization issues on Windows.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was failing because removed files can't be canonicalized, so when comparing path prefix with a canonicalized |
||
.with_status(101) | ||
.with_stderr_data(str![[r#" | ||
[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 uncommitted changes, pass the `--allow-dirty` flag | ||
|
||
"#]]) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn issue_13695_allow_dirty_vcs_info() { | ||
let p = project() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to think through how this PR might be disruptive to people's workflows and the most likely case I can come ip with is people being sloppy with version bumps and publishing which can run into #5979.