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!
This commit is contained in:
bors 2018-08-07 22:19:54 +00:00
commit 0e7a46e327
3 changed files with 22 additions and 10 deletions

View file

@ -27,7 +27,7 @@ failure = "0.1.2"
filetime = "0.2" filetime = "0.2"
flate2 = "1.0" flate2 = "1.0"
fs2 = "0.4" fs2 = "0.4"
git2 = "0.7.3" git2 = "0.7.5"
git2-curl = "0.8.1" git2-curl = "0.8.1"
glob = "0.2.11" glob = "0.2.11"
hex = "0.3" hex = "0.3"

View file

@ -59,7 +59,7 @@ pub fn package(ws: &Workspace, opts: &PackageOpts) -> CargoResult<Option<FileLoc
} }
if !opts.allow_dirty { if !opts.allow_dirty {
check_not_dirty(pkg, &src)?; check_not_dirty(pkg, &src, &config)?;
} }
let filename = format!("{}-{}.crate", pkg.name(), pkg.version()); let filename = format!("{}-{}.crate", pkg.name(), pkg.version());
@ -152,26 +152,36 @@ fn verify_dependencies(pkg: &Package) -> CargoResult<()> {
Ok(()) Ok(())
} }
fn check_not_dirty(p: &Package, src: &PathSource) -> CargoResult<()> { fn check_not_dirty(p: &Package, src: &PathSource, config: &Config) -> CargoResult<()> {
if let Ok(repo) = git2::Repository::discover(p.root()) { if let Ok(repo) = git2::Repository::discover(p.root()) {
if let Some(workdir) = repo.workdir() { if let Some(workdir) = repo.workdir() {
debug!( debug!("found a git repo at {:?}", workdir);
"found a git repo at {:?}, checking if index present",
workdir
);
let path = p.manifest_path(); let path = p.manifest_path();
let path = path.strip_prefix(workdir).unwrap_or(path); let path = path.strip_prefix(workdir).unwrap_or(path);
if let Ok(status) = repo.status_file(path) { if let Ok(status) = repo.status_file(path) {
if (status & git2::Status::IGNORED).is_empty() { if (status & git2::Status::IGNORED).is_empty() {
debug!("Cargo.toml found in repo, checking if dirty"); debug!(
"found (git) Cargo.toml at {:?} in workdir {:?}",
path, workdir
);
return git(p, src, &repo); return git(p, src, &repo);
} }
} }
config.shell().verbose(|shell| {
shell.warn(format!(
"No (git) Cargo.toml found at `{}` in workdir `{}`",
path.display(), workdir.display()
))
})?;
} }
} else {
config.shell().verbose(|shell| {
shell.warn(format!("No (git) VCS found for `{}`", p.root().display()))
})?;
} }
// No VCS recognized, we don't know if the directory is dirty or not, so we // No VCS with a checked in Cargo.toml found. so we don't know if the
// have to assume that it's clean. // directory is dirty or not, so we have to assume that it's clean.
return Ok(()); return Ok(());
fn git(p: &Package, src: &PathSource, repo: &git2::Repository) -> CargoResult<()> { fn git(p: &Package, src: &PathSource, repo: &git2::Repository) -> CargoResult<()> {

View file

@ -320,6 +320,7 @@ fn exclude() {
"\ "\
[WARNING] manifest has no description[..] [WARNING] manifest has no description[..]
See http://doc.crates.io/manifest.html#package-metadata for more info. See http://doc.crates.io/manifest.html#package-metadata for more info.
[WARNING] No (git) Cargo.toml found at `[..]` in workdir `[..]`
[PACKAGING] foo v0.0.1 ([..]) [PACKAGING] foo v0.0.1 ([..])
[WARNING] [..] file `dir_root_1/some_dir/file` WILL be excluded [..] [WARNING] [..] file `dir_root_1/some_dir/file` WILL be excluded [..]
See [..] See [..]
@ -409,6 +410,7 @@ fn include() {
"\ "\
[WARNING] manifest has no description[..] [WARNING] manifest has no description[..]
See http://doc.crates.io/manifest.html#package-metadata for more info. See http://doc.crates.io/manifest.html#package-metadata for more info.
[WARNING] No (git) Cargo.toml found at `[..]` in workdir `[..]`
[PACKAGING] foo v0.0.1 ([..]) [PACKAGING] foo v0.0.1 ([..])
[ARCHIVING] [..] [ARCHIVING] [..]
[ARCHIVING] [..] [ARCHIVING] [..]