Skip to content

Commit fde1e43

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 0e60ce6 commit fde1e43

File tree

4 files changed

+73
-28
lines changed

4 files changed

+73
-28
lines changed

src/cargo/ops/cargo_package/mod.rs

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

452452
// Check (git) repository state, getting the current commit hash.
453-
// TODO: where is the feature toggle?
454-
let use_gix = true;
455-
let vcs_info = if use_gix {
453+
let vcs_info = if ws.gctx().cli_unstable().gitoxide.is_some() {
456454
vcs::gix::check_repo_state(pkg, &src_files, ws, &opts)
457455
} else {
458456
vcs::check_repo_state(pkg, &src_files, ws, &opts)

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

Lines changed: 20 additions & 18 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)?
@@ -295,13 +307,6 @@ fn collect_statuses(
295307
continue;
296308
}
297309

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-
}
305310
dirty_files.push(path);
306311
}
307312
Ok(dirty_files_outside_of_package_root)
@@ -310,7 +315,6 @@ fn collect_statuses(
310315
/// Helper to collect dirty statuses while recursing into submodules.
311316
fn status_submodules(
312317
repo: &gix::Repository,
313-
workdir: &Path,
314318
dirty_files: &mut Vec<PathBuf>,
315319
dirty_files_outside_of_package_root: &mut Vec<PathBuf>,
316320
) -> CargoResult<()> {
@@ -321,12 +325,10 @@ fn status_submodules(
321325
// Ignore submodules that don't open, they are probably not initialized.
322326
// If its files are required, then the verification step should fail.
323327
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-
)?;
328+
let Some(workdir) = sub_repo.workdir() else {
329+
continue;
330+
};
331+
status_submodules(&sub_repo, dirty_files, dirty_files_outside_of_package_root)?;
330332
dirty_files_outside_of_package_root.extend(collect_statuses(
331333
&sub_repo,
332334
workdir,

tests/testsuite/git.rs

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

31763190
git::commit(&repo);
@@ -3207,7 +3221,20 @@ to proceed despite this and include the uncommitted changes, pass the `--allow-d
32073221
git_project
32083222
.cargo("package --no-verify")
32093223
.with_status(101)
3210-
.with_stderr_data(str![[r#"
3224+
.with_stderr_data(if cargo_uses_gitoxide() {
3225+
str![[r#"
3226+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
3227+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
3228+
[ERROR] 2 files in the working directory contain changes that were not yet committed into git:
3229+
3230+
src/.gitmodules
3231+
src/bar/mod.rs
3232+
3233+
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
3234+
3235+
"#]]
3236+
} else {
3237+
str![[r#"
32113238
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
32123239
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
32133240
[ERROR] 1 files in the working directory contain changes that were not yet committed into git:
@@ -3216,7 +3243,8 @@ src/.gitmodules
32163243
32173244
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
32183245
3219-
"#]])
3246+
"#]]
3247+
})
32203248
.run();
32213249

32223250
// Commit the submodule addition.

tests/testsuite/package.rs

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

6+
use cargo_test_support::git::cargo_uses_gitoxide;
67
use cargo_test_support::prelude::*;
78
use cargo_test_support::publish::validate_crate_contents;
89
use cargo_test_support::registry::{self, Package};
@@ -1466,13 +1467,29 @@ fn dirty_file_outside_pkg_root_inside_submodule() {
14661467
// This dirtiness should be detected in the future.
14671468
p.change_file("submodule/file.txt", "changed");
14681469

1469-
p.cargo("package --workspace --no-verify")
1470-
.with_stderr_data(str![[r#"
1470+
let mut execs = p.cargo("package --workspace --no-verify");
1471+
if cargo_uses_gitoxide() {
1472+
execs
1473+
.with_status(101)
1474+
.with_stderr_data(str![[r#"
1475+
[ERROR] 1 files in the working directory contain changes that were not yet committed into git:
1476+
1477+
isengard/src/file.txt
1478+
1479+
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
1480+
1481+
"#]])
1482+
.run();
1483+
} else {
1484+
// In `git2` this isn't currently implemented, but it could be.
1485+
execs
1486+
.with_stderr_data(str![[r#"
14711487
[PACKAGING] isengard v0.0.0 ([ROOT]/foo/isengard)
14721488
[PACKAGED] 6 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
14731489
14741490
"#]])
1475-
.run();
1491+
.run();
1492+
}
14761493
}
14771494

14781495
#[cargo_test]

0 commit comments

Comments
 (0)