Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn package(ws: &Workspace, opts: &PackageOpts) -> CargoResult<Option<FileLoc
}

if !opts.allow_dirty {
check_not_dirty(pkg, &src)?;
check_not_dirty(pkg, &src, &ws, &config)?;
}

let filename = format!("{}-{}.crate", pkg.name(), pkg.version());
Expand Down Expand Up @@ -152,26 +152,38 @@ fn verify_dependencies(pkg: &Package) -> 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<()> {
Expand Down
4 changes: 4 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] [..]
Expand All @@ -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] [..]
Expand Down Expand Up @@ -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 [..]
Expand Down Expand Up @@ -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] [..]
Expand Down