Skip to content

Commit 2c22de1

Browse files
committed
Improve verbose console and logging in package check_not_dirty
Also fixes some tests. However without a fix in git2-rs, this is currently expected to fail tests on windows (only), in informative ways.
1 parent 0b80061 commit 2c22de1

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn package(ws: &Workspace, opts: &PackageOpts) -> CargoResult<Option<FileLoc
5959
}
6060

6161
if !opts.allow_dirty {
62-
check_not_dirty(pkg, &src)?;
62+
check_not_dirty(pkg, &src, &config)?;
6363
}
6464

6565
let filename = format!("{}-{}.crate", pkg.name(), pkg.version());
@@ -152,26 +152,33 @@ fn verify_dependencies(pkg: &Package) -> CargoResult<()> {
152152
Ok(())
153153
}
154154

155-
fn check_not_dirty(p: &Package, src: &PathSource) -> CargoResult<()> {
155+
fn check_not_dirty(p: &Package, src: &PathSource, config: &Config) -> CargoResult<()> {
156156
if let Ok(repo) = git2::Repository::discover(p.root()) {
157157
if let Some(workdir) = repo.workdir() {
158-
debug!(
159-
"found a git repo at {:?}, checking if index present",
160-
workdir
161-
);
158+
debug!("found a git repo at {:?}", workdir);
162159
let path = p.manifest_path();
163160
let path = path.strip_prefix(workdir).unwrap_or(path);
164161
if let Ok(status) = repo.status_file(path) {
165162
if (status & git2::Status::IGNORED).is_empty() {
166-
debug!("Cargo.toml found in repo, checking if dirty");
163+
debug!("found (git) Cargo.toml at {:?}", path);
167164
return git(p, src, &repo);
168165
}
169166
}
167+
config.shell().verbose(|shell| {
168+
shell.warn(format!(
169+
"No (git) Cargo.toml found at ({})",
170+
path.display()
171+
))
172+
})?;
170173
}
174+
} else {
175+
config.shell().verbose(|shell| {
176+
shell.warn(format!("No (git) VCS found for ({})", p.root().display()))
177+
})?;
171178
}
172179

173-
// No VCS recognized, we don't know if the directory is dirty or not, so we
174-
// have to assume that it's clean.
180+
// No VCS with a checked in Cargo.toml found. so we don't know if the
181+
// directory is dirty or not, so we have to assume that it's clean.
175182
return Ok(());
176183

177184
fn git(p: &Package, src: &PathSource, repo: &git2::Repository) -> CargoResult<()> {

tests/testsuite/package.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ fn exclude() {
326326
"\
327327
[WARNING] manifest has no description[..]
328328
See http://doc.crates.io/manifest.html#package-metadata for more info.
329+
[WARNING] No (git) Cargo.toml found at ([..])
329330
[PACKAGING] foo v0.0.1 ([..])
330331
[WARNING] [..] file `dir_root_1[/]some_dir[/]file` WILL be excluded [..]
331332
See [..]
@@ -415,6 +416,7 @@ fn include() {
415416
"\
416417
[WARNING] manifest has no description[..]
417418
See http://doc.crates.io/manifest.html#package-metadata for more info.
419+
[WARNING] No (git) Cargo.toml found at ([..])
418420
[PACKAGING] foo v0.0.1 ([..])
419421
[ARCHIVING] [..]
420422
[ARCHIVING] [..]

0 commit comments

Comments
 (0)