Skip to content

Commit

Permalink
cli: branch: reject empty branch name consistently by "set"
Browse files Browse the repository at this point in the history
Though "branch set" can't create new branch, this should provide a better error
message.
  • Loading branch information
yuja committed Jun 20, 2024
1 parent d4e64c4 commit 5988a00
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cli/src/commands/branch/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}

Expand Down
3 changes: 2 additions & 1 deletion cli/src/commands/branch/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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>,
}

Expand Down
7 changes: 7 additions & 0 deletions cli/tests/test_branch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 5988a00

Please sign in to comment.