cli: branch: reject empty branch name consistently by "set"

Though "branch set" can't create new branch, this should provide a better error
message.
This commit is contained in:
Yuya Nishihara 2024-06-20 13:15:50 +09:00
parent d4e64c46b4
commit 5988a00ae4
3 changed files with 10 additions and 2 deletions

View file

@ -29,7 +29,7 @@ pub struct BranchCreateArgs {
revision: Option<RevisionArg>,
/// The branches to create
#[arg(required = true, value_parser=NonEmptyStringValueParser::new())]
#[arg(required = true, value_parser = NonEmptyStringValueParser::new())]
names: Vec<String>,
}

View file

@ -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<String>,
}

View file

@ -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 '<NAMES>...' but none was supplied
For more information, try '--help'.
"###);
}
#[test]