From d760263afb02c747a246bb0471a4f51e09075246 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 10 Apr 2025 10:10:31 -0400 Subject: [PATCH] fix(package): ignore status check failure Dirtiness check for symlinks is mostly informational. 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. --- src/cargo/ops/cargo_package/vcs.rs | 18 ++++++++++++++++-- tests/testsuite/package.rs | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_package/vcs.rs b/src/cargo/ops/cargo_package/vcs.rs index 4f57c568b..5f29a44d9 100644 --- a/src/cargo/ops/cargo_package/vcs.rs +++ b/src/cargo/ops/cargo_package/vcs.rs @@ -268,8 +268,22 @@ fn dirty_files_outside_pkg_root( // Handle files outside package root but under git workdir, .filter_map(|p| paths::strip_prefix_canonical(p, workdir).ok()) { - if repo.status_file(&rel_path)? != git2::Status::CURRENT { - dirty_files.insert(workdir.join(rel_path)); + match repo.status_file(&rel_path) { + Ok(git2::Status::CURRENT) => {} + Ok(_) => { + dirty_files.insert(workdir.join(rel_path)); + } + Err(e) => { + // Dirtiness check for symlinks is mostly informational. + // 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}", + rel_path.display(), + workdir.display() + ); + } } } Ok(dirty_files) diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 729866c6b..ed12768cf 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1467,9 +1467,9 @@ fn dirty_file_outside_pkg_root_inside_submodule() { p.change_file("submodule/file.txt", "changed"); p.cargo("package --workspace --no-verify") - .with_status(101) .with_stderr_data(str![[r#" -[ERROR] attempt to get status of nonexistent file 'submodule/file.txt'; class=Invalid (3); code=NotFound (-3) +[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard) +[PACKAGED] 6 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) "#]]) .run();