Skip to content

Commit ca1060b

Browse files
committed
fix(cargo-package): show dirty filepaths relative to git workdir
1 parent 2386104 commit ca1060b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ fn check_repo_state(
805805
return Ok(Some(VcsInfo { git, path_in_vcs }));
806806

807807
fn git(
808-
pkg: &Package,
808+
_pkg: &Package,
809809
src_files: &[PathBuf],
810810
repo: &git2::Repository,
811811
opts: &PackageOpts<'_>,
@@ -824,11 +824,12 @@ fn check_repo_state(
824824
// Find the intersection of dirty in git, and the src_files that would
825825
// be packaged. This is a lazy n^2 check, but seems fine with
826826
// thousands of files.
827+
let workdir = repo.workdir().unwrap();
827828
let mut dirty_src_files: Vec<_> = src_files
828829
.iter()
829830
.filter(|src_file| dirty_files.iter().any(|path| src_file.starts_with(path)))
830831
.map(|path| {
831-
path.strip_prefix(pkg.root())
832+
path.strip_prefix(workdir)
832833
.unwrap_or(path)
833834
.display()
834835
.to_string()

tests/testsuite/package.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,8 @@ fn dirty_workspace_package() {
12171217
[PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
12181218
[ERROR] 2 files in the working directory contain changes that were not yet committed into git:
12191219
1220-
src/lib.rs
1221-
src/main.rs
1220+
mordor/src/lib.rs
1221+
mordor/src/main.rs
12221222
12231223
to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag
12241224

0 commit comments

Comments
 (0)