Skip to content

Commit 0e7a46e

Browse files
committed
Auto merge of #5858 - dekellum:git-check-logging-and-test, r=alexcrichton
Improve verbose console and log for finding git repo in package check Third attempt to resolve #5823 by improving logging and tests. This exposes the issue to testing, via verbose console output and is dependent on alexcrichton/git2-rs#341 as just released in git2 0.7.5 crate. Thus tests *should* now pass on all platforms, incl. windows, but I also intend to bump the minimal git2 release dependency (in a subsequently added commit). cc: @Eh2406 thanks for your fix and help!
2 parents f67349c + fcd86f3 commit 0e7a46e

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ failure = "0.1.2"
2727
filetime = "0.2"
2828
flate2 = "1.0"
2929
fs2 = "0.4"
30-
git2 = "0.7.3"
30+
git2 = "0.7.5"
3131
git2-curl = "0.8.1"
3232
glob = "0.2.11"
3333
hex = "0.3"

src/cargo/ops/cargo_package.rs

+19-9
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,36 @@ 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!(
164+
"found (git) Cargo.toml at {:?} in workdir {:?}",
165+
path, workdir
166+
);
167167
return git(p, src, &repo);
168168
}
169169
}
170+
config.shell().verbose(|shell| {
171+
shell.warn(format!(
172+
"No (git) Cargo.toml found at `{}` in workdir `{}`",
173+
path.display(), workdir.display()
174+
))
175+
})?;
170176
}
177+
} else {
178+
config.shell().verbose(|shell| {
179+
shell.warn(format!("No (git) VCS found for `{}`", p.root().display()))
180+
})?;
171181
}
172182

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.
183+
// No VCS with a checked in Cargo.toml found. so we don't know if the
184+
// directory is dirty or not, so we have to assume that it's clean.
175185
return Ok(());
176186

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

tests/testsuite/package.rs

+2
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ fn exclude() {
320320
"\
321321
[WARNING] manifest has no description[..]
322322
See http://doc.crates.io/manifest.html#package-metadata for more info.
323+
[WARNING] No (git) Cargo.toml found at `[..]` in workdir `[..]`
323324
[PACKAGING] foo v0.0.1 ([..])
324325
[WARNING] [..] file `dir_root_1/some_dir/file` WILL be excluded [..]
325326
See [..]
@@ -409,6 +410,7 @@ fn include() {
409410
"\
410411
[WARNING] manifest has no description[..]
411412
See http://doc.crates.io/manifest.html#package-metadata for more info.
413+
[WARNING] No (git) Cargo.toml found at `[..]` in workdir `[..]`
412414
[PACKAGING] foo v0.0.1 ([..])
413415
[ARCHIVING] [..]
414416
[ARCHIVING] [..]

0 commit comments

Comments
 (0)