Skip to content

Commit

Permalink
Auto merge of #6802 - ehuss:new-empty-email, r=Eh2406
Browse files Browse the repository at this point in the history
new/init: Don't include email if it is empty.

For `cargo new` or `cargo init`, if the email address is empty, don't include an empty `<>` in the `authors` field in `Cargo.toml`. This can be useful if you want to include an email address in the git config, but you don't want it in new manifest files.

Closes #4892
  • Loading branch information
bors committed Mar 31, 2019
2 parents ede459e + 4282274 commit 4986d8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,13 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
(Some(name), Some(email), _, _)
| (Some(name), None, _, Some(email))
| (None, Some(email), name, _)
| (None, None, name, Some(email)) => format!("{} <{}>", name, email),
| (None, None, name, Some(email)) => {
if email.is_empty() {
name
} else {
format!("{} <{}>", name, email)
}
}
(Some(name), None, _, None) | (None, None, name, None) => name,
};

Expand Down
11 changes: 11 additions & 0 deletions tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,14 @@ fn new_with_bad_edition() {
.with_status(1)
.run();
}

#[test]
fn new_with_blank_email() {
cargo_process("new foo")
.env("CARGO_NAME", "Sen")
.env("CARGO_EMAIL", "")
.run();

let contents = fs::read_to_string(paths::root().join("foo/Cargo.toml")).unwrap();
assert!(contents.contains(r#"authors = ["Sen"]"#), contents);
}

0 comments on commit 4986d8c

Please sign in to comment.