diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index fb0ff6a21d3..ff66ffdce97 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -59,7 +59,7 @@ pub fn package(ws: &Workspace, opts: &PackageOpts) -> CargoResult CargoResult<()> { Ok(()) } -fn check_not_dirty(p: &Package, src: &PathSource) -> CargoResult<()> { - if let Ok(repo) = git2::Repository::discover(p.root()) { - if let Some(workdir) = repo.workdir() { - debug!( - "found a git repo at {:?}, checking if index present", - workdir - ); - let path = p.manifest_path(); - let path = path.strip_prefix(workdir).unwrap_or(path); - if let Ok(status) = repo.status_file(path) { - if (status & git2::Status::IGNORED).is_empty() { - debug!("Cargo.toml found in repo, checking if dirty"); - return git(p, src, &repo); +fn check_not_dirty( + p: &Package, + src: &PathSource, + ws: &Workspace, + config: &Config +) -> CargoResult<()> { + let res = git2::Repository::discover(p.root()) + .or_else(|_e| git2::Repository::discover(ws.root())); + match res { + Ok(repo) => { + if let Some(workdir) = repo.workdir() { + config.shell().verbose(|shell| { + shell.status("Checking", format!("git repo ({:?})", workdir)) + })?; + let path = p.manifest_path(); + let path = path.strip_prefix(workdir).unwrap_or(path); + if let Ok(status) = repo.status_file(path) { + if (status & git2::Status::IGNORED).is_empty() { + debug!("Cargo.toml found in repo, checking if dirty"); + return git(p, src, &repo); + } } } } + Err(ref r) => { + config.shell().verbose(|shell| { + shell.warn(format!("No (git) VCS found: {:?}", r)) + })?; + } } - - // No VCS recognized, we don't know if the directory is dirty or not, so we - // have to assume that it's clean. + // No VCS recognized, we don't know if the directory is dirty or not, so + // we have to assume that it's clean. return Ok(()); fn git(p: &Package, src: &PathSource, repo: &git2::Repository) -> CargoResult<()> { diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index e00f6517888..a15aa3b0ee4 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -172,6 +172,7 @@ fn package_verbose() { "\ [WARNING] manifest has no description[..] See http://doc.crates.io/manifest.html#package-metadata for more info. +[CHECKING] git repo ([..]) [PACKAGING] foo v0.0.1 ([..]) [ARCHIVING] [..] [ARCHIVING] [..] @@ -190,6 +191,7 @@ See http://doc.crates.io/manifest.html#package-metadata for more info. "\ [WARNING] manifest has no description[..] See http://doc.crates.io/manifest.html#package-metadata for more info. +[CHECKING] git repo ([..]) [PACKAGING] a v0.0.1 ([..]) [ARCHIVING] [..] [ARCHIVING] [..] @@ -326,6 +328,7 @@ fn exclude() { "\ [WARNING] manifest has no description[..] See http://doc.crates.io/manifest.html#package-metadata for more info. +[CHECKING] git repo ([..]) [PACKAGING] foo v0.0.1 ([..]) [WARNING] [..] file `dir_root_1[/]some_dir[/]file` WILL be excluded [..] See [..] @@ -415,6 +418,7 @@ fn include() { "\ [WARNING] manifest has no description[..] See http://doc.crates.io/manifest.html#package-metadata for more info. +[CHECKING] git repo ([..]) [PACKAGING] foo v0.0.1 ([..]) [ARCHIVING] [..] [ARCHIVING] [..]