Skip to content

Commit 982eb2d

Browse files
committed
fix(package): show dirty filepaths relative to git workdir
1 parent ecc8e37 commit 982eb2d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ fn check_repo_state(
796796
.and_then(|p| p.to_str())
797797
.unwrap_or("")
798798
.replace("\\", "/");
799-
let Some(git) = git(p, src_files, &repo, &opts)? else {
799+
let Some(git) = git(src_files, &repo, &opts)? else {
800800
// If the git repo lacks essensial field like `sha1`, and since this field exists from the beginning,
801801
// then don't generate the corresponding file in order to maintain consistency with past behavior.
802802
return Ok(None);
@@ -805,7 +805,6 @@ fn check_repo_state(
805805
return Ok(Some(VcsInfo { git, path_in_vcs }));
806806

807807
fn git(
808-
pkg: &Package,
809808
src_files: &[PathBuf],
810809
repo: &git2::Repository,
811810
opts: &PackageOpts<'_>,
@@ -824,11 +823,12 @@ fn check_repo_state(
824823
// Find the intersection of dirty in git, and the src_files that would
825824
// be packaged. This is a lazy n^2 check, but seems fine with
826825
// thousands of files.
826+
let workdir = repo.workdir().unwrap();
827827
let mut dirty_src_files: Vec<_> = src_files
828828
.iter()
829829
.filter(|src_file| dirty_files.iter().any(|path| src_file.starts_with(path)))
830830
.map(|path| {
831-
path.strip_prefix(pkg.root())
831+
path.strip_prefix(workdir)
832832
.unwrap_or(path)
833833
.display()
834834
.to_string()

tests/testsuite/package.rs

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

0 commit comments

Comments
 (0)