Skip to content

Commit f768d42

Browse files
committed
use proper feature toggle to enable gitoxide for cargo package
While at it, adjust two test expectations to deal with improved detail of status checks.
1 parent a761b9a commit f768d42

File tree

4 files changed

+78
-37
lines changed

4 files changed

+78
-37
lines changed

src/cargo/ops/cargo_package/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,7 @@ fn prepare_archive(
479479
let src_files = src.list_files(pkg)?;
480480

481481
// Check (git) repository state, getting the current commit hash.
482-
// TODO: where is the feature toggle?
483-
let use_gix = true;
484-
let vcs_info = if use_gix {
482+
let vcs_info = if ws.gctx().cli_unstable().gitoxide.is_some() {
485483
vcs::gix::check_repo_state(pkg, &src_files, ws, &opts)
486484
} else {
487485
vcs::check_repo_state(pkg, &src_files, ws, &opts)

src/cargo/ops/cargo_package/vcs/gix.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::{CargoResult, GlobalContext};
66
use anyhow::Context;
77
use cargo_util::paths;
88
use gix::bstr::ByteSlice;
9-
use gix::diff::rewrites::tracker::Change;
109
use gix::dir::walk::EmissionMode;
1110
use gix::index::entry::Mode;
1211
use gix::status::tree_index::TrackRenames;
@@ -182,13 +181,11 @@ fn git(
182181
relative_package_root(repo, pkg.root()).as_deref(),
183182
&mut dirty_files,
184183
)?;
185-
// super::collect_statuses(git_repo, &[pathspec.as_str()], &mut dirty_files)?;
186184

187185
// Include each submodule so that the error message can provide
188186
// specifically *which* files in a submodule are modified.
189187
status_submodules(
190188
repo,
191-
workdir,
192189
&mut dirty_files,
193190
&mut dirty_files_outside_of_package_root,
194191
)?;
@@ -199,7 +196,22 @@ fn git(
199196
let cwd = ws.gctx().cwd();
200197
let mut dirty_src_files: Vec<_> = src_files
201198
.iter()
202-
.filter(|src_file| dirty_files.iter().any(|path| src_file.starts_with(path)))
199+
.filter(|src_file| {
200+
if let Some(canon_src_file) = src_file.is_symlink_or_under_symlink().then(|| {
201+
gix::path::realpath_opts(
202+
&src_file,
203+
ws.gctx().cwd(),
204+
gix::path::realpath::MAX_SYMLINKS,
205+
)
206+
.unwrap_or_else(|_| src_file.to_path_buf())
207+
}) {
208+
dirty_files
209+
.iter()
210+
.any(|path| canon_src_file.starts_with(path))
211+
} else {
212+
dirty_files.iter().any(|path| src_file.starts_with(path))
213+
}
214+
})
203215
.map(|p| p.as_ref())
204216
.chain(
205217
dirty_files_outside_pkg_root(ws, pkg, &dirty_files_outside_of_package_root, src_files)?
@@ -248,9 +260,10 @@ fn collect_statuses(
248260
.status(gix::progress::Discard)?
249261
.dirwalk_options(|opts| {
250262
opts.emit_untracked(gix::dir::walk::EmissionMode::Matching)
251-
// Also pick up ignored files (but not entire directories)
263+
// Also pick up ignored files or whole directories
252264
// to specifically catch overzealously ignored source files.
253-
// Later we will match these dirs by prefix.
265+
// Later we will match these dirs by prefix, which is why collapsing
266+
// them is desirable here.
254267
.emit_ignored(Some(EmissionMode::CollapseDirectory))
255268
.emit_tracked(false)
256269
.recurse_repositories(false)
@@ -295,13 +308,6 @@ fn collect_statuses(
295308
continue;
296309
}
297310

298-
// We completely ignore submodules
299-
if matches!(
300-
status,
301-
gix::status::Item::TreeIndex(change) if change.entry_mode().is_commit())
302-
{
303-
continue;
304-
}
305311
dirty_files.push(path);
306312
}
307313
Ok(dirty_files_outside_of_package_root)
@@ -310,7 +316,6 @@ fn collect_statuses(
310316
/// Helper to collect dirty statuses while recursing into submodules.
311317
fn status_submodules(
312318
repo: &gix::Repository,
313-
workdir: &Path,
314319
dirty_files: &mut Vec<PathBuf>,
315320
dirty_files_outside_of_package_root: &mut Vec<PathBuf>,
316321
) -> CargoResult<()> {
@@ -321,12 +326,10 @@ fn status_submodules(
321326
// Ignore submodules that don't open, they are probably not initialized.
322327
// If its files are required, then the verification step should fail.
323328
if let Some(sub_repo) = submodule.open()? {
324-
status_submodules(
325-
&sub_repo,
326-
workdir,
327-
dirty_files,
328-
dirty_files_outside_of_package_root,
329-
)?;
329+
let Some(workdir) = sub_repo.workdir() else {
330+
continue;
331+
};
332+
status_submodules(&sub_repo, dirty_files, dirty_files_outside_of_package_root)?;
330333
dirty_files_outside_of_package_root.extend(collect_statuses(
331334
&sub_repo,
332335
workdir,
@@ -391,15 +394,10 @@ fn dirty_files_outside_pkg_root(
391394
)
392395
.unwrap_or_else(|_| src_file.to_owned());
393396

394-
if dirty_files_outside_of_package_root
397+
dirty_files_outside_of_package_root
395398
.iter()
396399
.any(|p| canon_src_path.starts_with(p))
397-
{
398-
// Use the canonicalized path as later we want to truncate it by the CWD, which is also canonicalized.
399-
Some(canon_src_path)
400-
} else {
401-
None
402-
}
400+
.then_some(canon_src_path)
403401
})
404402
.collect();
405403
Ok(dirty_files)

tests/testsuite/git.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,7 +3159,20 @@ fn dirty_submodule() {
31593159
git_project
31603160
.cargo("package --no-verify")
31613161
.with_status(101)
3162-
.with_stderr_data(str![[r#"
3162+
.with_stderr_data(if cargo_uses_gitoxide() {
3163+
str![[r#"
3164+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
3165+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
3166+
[ERROR] 2 files in the working directory contain changes that were not yet committed into git:
3167+
3168+
.gitmodules
3169+
src/lib.rs
3170+
3171+
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
3172+
3173+
"#]]
3174+
} else {
3175+
str![[r#"
31633176
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
31643177
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
31653178
[ERROR] 1 files in the working directory contain changes that were not yet committed into git:
@@ -3168,7 +3181,8 @@ See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for
31683181
31693182
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
31703183
3171-
"#]])
3184+
"#]]
3185+
})
31723186
.run();
31733187

31743188
git::commit(&repo);
@@ -3205,7 +3219,20 @@ to proceed despite this and include the uncommitted changes, pass the `--allow-d
32053219
git_project
32063220
.cargo("package --no-verify")
32073221
.with_status(101)
3208-
.with_stderr_data(str![[r#"
3222+
.with_stderr_data(if cargo_uses_gitoxide() {
3223+
str![[r#"
3224+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
3225+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
3226+
[ERROR] 2 files in the working directory contain changes that were not yet committed into git:
3227+
3228+
src/.gitmodules
3229+
src/bar/mod.rs
3230+
3231+
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
3232+
3233+
"#]]
3234+
} else {
3235+
str![[r#"
32093236
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
32103237
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
32113238
[ERROR] 1 files in the working directory contain changes that were not yet committed into git:
@@ -3214,7 +3241,8 @@ src/.gitmodules
32143241
32153242
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
32163243
3217-
"#]])
3244+
"#]]
3245+
})
32183246
.run();
32193247

32203248
// Commit the submodule addition.

tests/testsuite/package.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::path::Path;
55

66
use crate::prelude::*;
77
use crate::utils::cargo_process;
8+
use cargo_test_support::git::cargo_uses_gitoxide;
89
use cargo_test_support::publish::validate_crate_contents;
910
use cargo_test_support::registry::{self, Package};
1011
use cargo_test_support::{
@@ -1473,13 +1474,29 @@ fn dirty_file_outside_pkg_root_inside_submodule() {
14731474
// This dirtiness should be detected in the future.
14741475
p.change_file("submodule/file.txt", "changed");
14751476

1476-
p.cargo("package --workspace --no-verify")
1477-
.with_stderr_data(str![[r#"
1477+
let mut execs = p.cargo("package --workspace --no-verify");
1478+
if cargo_uses_gitoxide() {
1479+
execs
1480+
.with_status(101)
1481+
.with_stderr_data(str![[r#"
1482+
[ERROR] 1 files in the working directory contain changes that were not yet committed into git:
1483+
1484+
isengard/src/file.txt
1485+
1486+
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
1487+
1488+
"#]])
1489+
.run();
1490+
} else {
1491+
// In `git2` this isn't currently implemented, but it could be.
1492+
execs
1493+
.with_stderr_data(str![[r#"
14781494
[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard)
14791495
[PACKAGED] 6 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
14801496
14811497
"#]])
1482-
.run();
1498+
.run();
1499+
}
14831500
}
14841501

14851502
#[cargo_test]

0 commit comments

Comments
 (0)