Skip to content

Commit 3dd6327

Browse files
authored
Auto merge of #3068 - binarybirchtree:generalize-error-message, r=alexcrichton
Generalize error message used by both `cargo package` and `cargo publish`. Resolves issue #3061. This pull request updates the wording of the error message in question to be applicable to both `cargo package` and `cargo publish`, and adds a test case for the example in the issue description.
2 parents b78beb1 + ee32e10 commit 3dd6327

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/cargo/ops/cargo_package.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ fn check_not_dirty(p: &Package, src: &PathSource) -> CargoResult<()> {
173173
Ok(())
174174
} else {
175175
bail!("{} dirty files found in the working directory:\n\n{}\n\n\
176-
to publish despite this, pass `--allow-dirty` to \
177-
`cargo publish`",
176+
to proceed despite this, pass the `--allow-dirty` flag",
178177
dirty.len(), dirty.join("\n"))
179178
}
180179
}

tests/package.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern crate hamcrest;
66
extern crate tar;
77
extern crate cargo;
88

9-
use std::fs::File;
9+
use std::fs::{File, OpenOptions};
1010
use std::io::prelude::*;
1111
use std::path::{Path, PathBuf};
1212

@@ -544,3 +544,37 @@ Caused by:
544544
[..]
545545
"));
546546
}
547+
548+
#[test]
549+
fn do_not_package_if_repository_is_dirty() {
550+
// Create a Git repository containing a minimal Rust project.
551+
git::repo(&paths::root().join("foo"))
552+
.file("Cargo.toml", r#"
553+
[project]
554+
name = "foo"
555+
version = "0.0.1"
556+
license = "MIT"
557+
description = "foo"
558+
documentation = "foo"
559+
homepage = "foo"
560+
repository = "foo"
561+
"#)
562+
.file("src/main.rs", "fn main() {}")
563+
.build();
564+
565+
// Modify Cargo.toml without committing the change.
566+
let p = project("foo");
567+
let manifest_path = p.root().join("Cargo.toml");
568+
let mut manifest = t!(OpenOptions::new().append(true).open(manifest_path));
569+
t!(writeln!(manifest, ""));
570+
571+
assert_that(p.cargo("package"),
572+
execs().with_status(101)
573+
.with_stderr("\
574+
error: 1 dirty files found in the working directory:
575+
576+
Cargo.toml
577+
578+
to proceed despite this, pass the `--allow-dirty` flag
579+
"));
580+
}

tests/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ error: 1 dirty files found in the working directory:
207207
208208
bar
209209
210-
to publish despite this, pass `--allow-dirty` to `cargo publish`
210+
to proceed despite this, pass the `--allow-dirty` flag
211211
"));
212212
}
213213

0 commit comments

Comments
 (0)