Skip to content

Commit e5f8f64

Browse files
committed
fix: revert the behavior checking lockfile's VCS
Lockfile might be gitignore'd, So it never shows up in `git status`. However, `cargo packag` vcs checks actually performs `git status --untracked --ignored`. It is a bit confusing that lockfile is ignored but still counts as dirty from the report of `cargo package`. There are some more nuances: We check lockfile's VCS status if the lockfile is ouside the current package root. That means a non-workspace Cargo package will not have this VCS check. I don't think it is good that we have diverged behaviors Hence this revert. We can always re-evaluate later, as we've reserved rooms for doing more dirty checks. #14967 (comment)
1 parent cc585c0 commit e5f8f64

File tree

2 files changed

+0
-163
lines changed

2 files changed

+0
-163
lines changed

src/cargo/ops/cargo_package/vcs.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use tracing::debug;
1111

1212
use crate::core::Package;
1313
use crate::core::Workspace;
14-
use crate::ops::lockfile::LOCKFILE_NAME;
1514
use crate::sources::PathEntry;
1615
use crate::CargoResult;
1716
use crate::GlobalContext;
@@ -236,15 +235,10 @@ fn git(
236235
/// * `package.readme` and `package.license-file` pointing to paths outside package root
237236
/// * symlinks targets reside outside package root
238237
/// * Any change in the root workspace manifest, regardless of what has changed.
239-
/// * Changes in the lockfile [^1].
240238
///
241239
/// This is required because those paths may link to a file outside the
242240
/// current package root, but still under the git workdir, affecting the
243241
/// final packaged `.crate` file.
244-
///
245-
/// [^1]: Lockfile might be re-generated if it is too out of sync with the manifest.
246-
/// Therefore, even you have a modified lockfile,
247-
/// you might still get a new fresh one that matches what is in git index.
248242
fn dirty_files_outside_pkg_root(
249243
ws: &Workspace<'_>,
250244
pkg: &Package,
@@ -263,41 +257,12 @@ fn dirty_files_outside_pkg_root(
263257
.map(|path| paths::normalize_path(&pkg_root.join(path)))
264258
.collect();
265259

266-
// Unlike other files, lockfile is allowed to be missing,
267-
// and can be generated during packaging.
268-
// We skip checking when it is missing in both workdir and git index,
269-
// otherwise cargo will fail with git2 not found error.
270-
let lockfile_path = ws.lock_root().as_path_unlocked().join(LOCKFILE_NAME);
271-
let lockfile_path = if lockfile_path.exists() {
272-
Some(lockfile_path)
273-
} else if let Ok(rel_path) = paths::normalize_path(&lockfile_path).strip_prefix(workdir) {
274-
// We don't canonicalize here because non-existing path can't be canonicalized.
275-
match repo.status_file(&rel_path) {
276-
Ok(s) if s != git2::Status::CURRENT => {
277-
dirty_files.insert(lockfile_path);
278-
}
279-
// Unmodified
280-
Ok(_) => {}
281-
Err(e) => {
282-
debug!(
283-
"check git status failed for `{}` in workdir `{}`: {e}",
284-
rel_path.display(),
285-
workdir.display(),
286-
);
287-
}
288-
}
289-
None
290-
} else {
291-
None
292-
};
293-
294260
for rel_path in src_files
295261
.iter()
296262
.filter(|p| p.is_symlink_or_under_symlink())
297263
.map(|p| p.as_ref().as_path())
298264
.chain(metadata_paths.iter().map(AsRef::as_ref))
299265
.chain([ws.root_manifest()])
300-
.chain(lockfile_path.as_deref().into_iter())
301266
// If inside package root. Don't bother checking git status.
302267
.filter(|p| paths::strip_prefix_canonical(p, pkg_root).is_err())
303268
// Handle files outside package root but under git workdir,

tests/testsuite/package.rs

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use std::fs::{self, read_to_string, File};
44
use std::path::Path;
55

6-
use cargo_test_support::compare::assert_e2e;
76
use cargo_test_support::prelude::*;
87
use cargo_test_support::publish::validate_crate_contents;
98
use cargo_test_support::registry::{self, Package};
@@ -1426,133 +1425,6 @@ edition = "2021"
14261425
);
14271426
}
14281427

1429-
#[cargo_test]
1430-
fn dirty_ws_lockfile_dirty() {
1431-
let (p, repo) = git::new_repo("foo", |p| {
1432-
p.file(
1433-
"Cargo.toml",
1434-
r#"
1435-
[workspace]
1436-
members = ["isengard"]
1437-
resolver = "2"
1438-
[workspace.package]
1439-
edition = "2015"
1440-
"#,
1441-
)
1442-
.file(
1443-
"isengard/Cargo.toml",
1444-
r#"
1445-
[package]
1446-
name = "isengard"
1447-
edition.workspace = true
1448-
homepage = "saruman"
1449-
description = "saruman"
1450-
license = "MIT"
1451-
"#,
1452-
)
1453-
.file("isengard/src/lib.rs", "")
1454-
});
1455-
git::commit(&repo);
1456-
1457-
p.cargo("package --workspace --no-verify")
1458-
.with_stderr_data(str![[r#"
1459-
[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard)
1460-
[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
1461-
1462-
"#]])
1463-
.run();
1464-
1465-
// lockfile is untracked.
1466-
p.cargo("generate-lockfile").run();
1467-
p.cargo("package --workspace --no-verify")
1468-
.with_status(101)
1469-
.with_stderr_data(str![[r#"
1470-
[ERROR] 1 files in the working directory contain changes that were not yet committed into git:
1471-
1472-
Cargo.lock
1473-
1474-
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
1475-
1476-
"#]])
1477-
.run();
1478-
1479-
// lockfile is tracked.
1480-
p.cargo("clean").run();
1481-
git::add(&repo);
1482-
git::commit(&repo);
1483-
p.cargo("package --workspace --no-verify")
1484-
.with_stderr_data(str![[r#"
1485-
[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard)
1486-
[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
1487-
1488-
"#]])
1489-
.run();
1490-
1491-
// Simulate that Cargo.lock had some outdated but SemVer compat dependency changes.
1492-
Package::new("dep", "1.0.0").publish();
1493-
Package::new("dep", "1.1.0").publish();
1494-
p.cargo("clean").run();
1495-
p.cargo("add dep@1").run();
1496-
git::add(&repo);
1497-
git::commit(&repo);
1498-
// make sure we have [email protected] in lockfile
1499-
assert_e2e().eq(
1500-
&p.read_lockfile(),
1501-
str![[r##"
1502-
# This file is automatically @generated by Cargo.
1503-
# It is not intended for manual editing.
1504-
version = 4
1505-
1506-
[[package]]
1507-
name = "dep"
1508-
version = "1.1.0"
1509-
source = "registry+https://github.com/rust-lang/crates.io-index"
1510-
checksum = "77d3d6a4f2203d590707cc803c94afbe36393bbdba757ef66986f39159eaab51"
1511-
1512-
[[package]]
1513-
name = "isengard"
1514-
version = "0.0.0"
1515-
dependencies = [
1516-
"dep",
1517-
]
1518-
1519-
"##]],
1520-
);
1521-
p.cargo("update dep --precise 1.0.0")
1522-
.with_stderr_data(str![[r#"
1523-
[UPDATING] `dummy-registry` index
1524-
[DOWNGRADING] dep v1.1.0 -> v1.0.0
1525-
1526-
"#]])
1527-
.run();
1528-
p.cargo("package --workspace --no-verify")
1529-
.with_status(101)
1530-
.with_stderr_data(str![[r#"
1531-
[ERROR] 1 files in the working directory contain changes that were not yet committed into git:
1532-
1533-
Cargo.lock
1534-
1535-
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
1536-
1537-
"#]])
1538-
.run();
1539-
1540-
// Now check if it is considered dirty when removed.
1541-
p.cargo("clean").run();
1542-
fs::remove_file(p.root().join("Cargo.lock")).unwrap();
1543-
p.cargo("package --workspace --no-verify")
1544-
.with_status(101)
1545-
.with_stderr_data(str![[r#"
1546-
[ERROR] 1 files in the working directory contain changes that were not yet committed into git:
1547-
1548-
Cargo.lock
1549-
1550-
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
1551-
1552-
"#]])
1553-
.run();
1554-
}
1555-
15561428
#[cargo_test]
15571429
fn issue_13695_allow_dirty_vcs_info() {
15581430
let p = project()

0 commit comments

Comments
 (0)