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.
This commit is contained in:
Weihang Lo 2025-04-10 10:10:31 -04:00
parent 79473988e5
commit d760263afb
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
2 changed files with 18 additions and 4 deletions

View File

@ -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)

View File

@ -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();