diff --git a/src/cli_util.rs b/src/cli_util.rs index 4baffc533..8aec77f82 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -797,6 +797,14 @@ impl WorkspaceCommandHelper { let git_repo = self.repo.store().git_repo().unwrap(); git::export_refs(&self.repo, &git_repo)?; } + let settings = ui.settings(); + if settings.user_name() == UserSettings::user_name_placeholder() + || settings.user_email() == UserSettings::user_email_placeholder() + { + ui.write_warn(r#"Name and email not configured. Add something like the following to $HOME/.jjconfig.toml: + user.name = "Some One" + user.email = "someone@example.com""#)?; + } Ok(()) } } diff --git a/tests/test_global_opts.rs b/tests/test_global_opts.rs index 6edaf020f..006875fb4 100644 --- a/tests/test_global_opts.rs +++ b/tests/test_global_opts.rs @@ -144,6 +144,35 @@ fn test_invalid_config() { "###); } +#[test] +fn test_no_user_configured() { + // Test that the user is reminded if they haven't configured their name or email + let test_env = TestEnvironment::default(); + test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]); + let repo_path = test_env.env_root().join("repo"); + + let assert = test_env + .jj_cmd(&repo_path, &["describe", "-m", "without name"]) + .env_remove("JJ_USER") + .assert() + .success(); + insta::assert_snapshot!(get_stderr_string(&assert), @r###" + Name and email not configured. Add something like the following to $HOME/.jjconfig.toml: + user.name = "Some One" + user.email = "someone@example.com" + "###); + let assert = test_env + .jj_cmd(&repo_path, &["describe", "-m", "without email"]) + .env_remove("JJ_EMAIL") + .assert() + .success(); + insta::assert_snapshot!(get_stderr_string(&assert), @r###" + Name and email not configured. Add something like the following to $HOME/.jjconfig.toml: + user.name = "Some One" + user.email = "someone@example.com" + "###); +} + #[test] fn test_help() { // Test that global options are separated out in the help output