From 5988a00ae45621512f16a4269e4ca56589f50718 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 20 Jun 2024 13:15:50 +0900 Subject: [PATCH] cli: branch: reject empty branch name consistently by "set" Though "branch set" can't create new branch, this should provide a better error message. --- cli/src/commands/branch/create.rs | 2 +- cli/src/commands/branch/set.rs | 3 ++- cli/tests/test_branch_command.rs | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cli/src/commands/branch/create.rs b/cli/src/commands/branch/create.rs index 21a23224f..42cd8ee95 100644 --- a/cli/src/commands/branch/create.rs +++ b/cli/src/commands/branch/create.rs @@ -29,7 +29,7 @@ pub struct BranchCreateArgs { revision: Option, /// The branches to create - #[arg(required = true, value_parser=NonEmptyStringValueParser::new())] + #[arg(required = true, value_parser = NonEmptyStringValueParser::new())] names: Vec, } diff --git a/cli/src/commands/branch/set.rs b/cli/src/commands/branch/set.rs index 5ae50dc69..06b8e0476 100644 --- a/cli/src/commands/branch/set.rs +++ b/cli/src/commands/branch/set.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use clap::builder::NonEmptyStringValueParser; use jj_lib::object_id::ObjectId as _; use jj_lib::op_store::RefTarget; @@ -32,7 +33,7 @@ pub struct BranchSetArgs { allow_backwards: bool, /// The branches to update - #[arg(required = true)] + #[arg(required = true, value_parser = NonEmptyStringValueParser::new())] names: Vec, } diff --git a/cli/tests/test_branch_command.rs b/cli/tests/test_branch_command.rs index f4d514746..c706e6248 100644 --- a/cli/tests/test_branch_command.rs +++ b/cli/tests/test_branch_command.rs @@ -88,6 +88,13 @@ fn test_branch_empty_name() { For more information, try '--help'. "###); + + let stderr = test_env.jj_cmd_cli_error(&repo_path, &["branch", "set", ""]); + insta::assert_snapshot!(stderr, @r###" + error: a value is required for '...' but none was supplied + + For more information, try '--help'. + "###); } #[test]