Skip to content

Commit d107843

Browse files
authored
Merge pull request #2486 from eureka-cpu/eureka-cpu/2485
fix `init --title` option failure when git user is not configured
2 parents 9096012 + 8f024da commit d107843

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/cmd/init.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
7474
if let Some(author) = get_author_name() {
7575
debug!("Obtained user name from gitconfig: {:?}", author);
7676
config.book.authors.push(author);
77-
builder.with_config(config);
7877
}
7978

79+
builder.with_config(config);
8080
builder.build()?;
8181
println!("\nAll done, no errors...");
8282

tests/cli/init.rs

+23
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,26 @@ fn base_mdbook_init_can_skip_confirmation_prompts() {
2222

2323
assert!(!temp.path().join(".gitignore").exists());
2424
}
25+
26+
/// Run `mdbook init` with `--title` without git config.
27+
///
28+
/// Regression test for https://github.com/rust-lang/mdBook/issues/2485
29+
#[test]
30+
fn no_git_config_with_title() {
31+
let temp = DummyBook::new().build().unwrap();
32+
33+
// doesn't exist before
34+
assert!(!temp.path().join("book").exists());
35+
36+
let mut cmd = mdbook_cmd();
37+
cmd.args(["init", "--title", "Example title"])
38+
.current_dir(temp.path())
39+
.env("GIT_CONFIG_GLOBAL", "")
40+
.env("GIT_CONFIG_NOSYSTEM", "1");
41+
cmd.assert()
42+
.success()
43+
.stdout(predicates::str::contains("\nAll done, no errors...\n"));
44+
45+
let config = Config::from_disk(temp.path().join("book.toml")).unwrap();
46+
assert_eq!(config.book.title.as_deref(), Some("Example title"));
47+
}

0 commit comments

Comments
 (0)