Skip to content

Commit

Permalink
cli: error when jj rebase -b is used without --destination
Browse files Browse the repository at this point in the history
Closes #4770.
  • Loading branch information
bnjmnt4n committed Nov 7, 2024
1 parent f9cfa5c commit 1c817f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
17 changes: 6 additions & 11 deletions cli/src/commands/rebase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,7 @@ pub(crate) struct RebaseArgs {
/// -d=dst`.
///
/// If none of `-b`, `-s`, or `-r` is provided, then the default is `-b @`.
#[arg(
long,
short,
conflicts_with = "insert_after",
conflicts_with = "insert_before"
)]
#[arg(long, short)]
branch: Vec<RevisionArg>,

/// Rebase specified revision(s) together with their trees of descendants
Expand Down Expand Up @@ -268,11 +263,11 @@ pub(crate) fn cmd_rebase(
&rebase_options,
)?;
} else {
let destination = args
.destination
.destination
.as_ref()
.expect("clap should enforce -d when used with -b");
let Some(destination) = args.destination.destination.as_ref() else {
return Err(cli_error(
"The argument `--destination <DESTINATION>` is required to rebase a whole branch",
));
};
let new_parents = workspace_command
.resolve_some_revsets_default_single(ui, destination)?
.into_iter()
Expand Down
24 changes: 10 additions & 14 deletions cli/tests/test_rebase_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ fn test_rebase_invalid() {
For more information, try '--help'.
"###);

// --after with implicit -b
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["rebase", "--after", "a"]);
insta::assert_snapshot!(stderr, @"Error: The argument `--destination <DESTINATION>` is required to rebase a whole branch");

// --before with implicit -b
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["rebase", "--before", "a"]);
insta::assert_snapshot!(stderr, @"Error: The argument `--destination <DESTINATION>` is required to rebase a whole branch");

// Both -r and -s
let stderr =
test_env.jj_cmd_cli_error(&repo_path, &["rebase", "-r", "a", "-s", "a", "-d", "b"]);
Expand Down Expand Up @@ -98,13 +106,7 @@ fn test_rebase_invalid() {

// -b with --after
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["rebase", "-b", "a", "--after", "b"]);
insta::assert_snapshot!(stderr, @r###"
error: the argument '--branch <BRANCH>' cannot be used with '--insert-after <INSERT_AFTER>'
Usage: jj rebase --branch <BRANCH> <--destination <DESTINATION>|--insert-after <INSERT_AFTER>|--insert-before <INSERT_BEFORE>>
For more information, try '--help'.
"###);
insta::assert_snapshot!(stderr, @"Error: The argument `--destination <DESTINATION>` is required to rebase a whole branch");

// Both -d and --before
let stderr = test_env.jj_cmd_cli_error(
Expand All @@ -121,13 +123,7 @@ fn test_rebase_invalid() {

// -b with --before
let stderr = test_env.jj_cmd_cli_error(&repo_path, &["rebase", "-b", "a", "--before", "b"]);
insta::assert_snapshot!(stderr, @r###"
error: the argument '--branch <BRANCH>' cannot be used with '--insert-before <INSERT_BEFORE>'
Usage: jj rebase --branch <BRANCH> <--destination <DESTINATION>|--insert-after <INSERT_AFTER>|--insert-before <INSERT_BEFORE>>
For more information, try '--help'.
"###);
insta::assert_snapshot!(stderr, @"Error: The argument `--destination <DESTINATION>` is required to rebase a whole branch");

// Rebase onto self with -r
let stderr = test_env.jj_cmd_failure(&repo_path, &["rebase", "-r", "a", "-d", "a"]);
Expand Down

0 comments on commit 1c817f8

Please sign in to comment.