diff --git a/cli/src/commands/new.rs b/cli/src/commands/new.rs index 49d187a87..e428fa965 100644 --- a/cli/src/commands/new.rs +++ b/cli/src/commands/new.rs @@ -42,7 +42,7 @@ pub(crate) struct NewArgs { #[arg(default_value = "@")] pub(crate) revisions: Vec, /// Ignored (but lets you pass `-r` for consistency with other commands) - #[arg(short = 'r', hide = true)] + #[arg(short = 'r', hide = true, overrides_with = "unused_revision")] unused_revision: bool, /// The change description to use #[arg(long = "message", short, value_name = "MESSAGE")] @@ -51,10 +51,24 @@ pub(crate) struct NewArgs { #[arg(long, short = 'L', hide = true)] allow_large_revsets: bool, /// Insert the new change between the target commit(s) and their children - #[arg(long, short = 'A', visible_alias = "after")] + // + // Repeating this flag is allowed, but has no effect. + #[arg( + long, + short = 'A', + visible_alias = "after", + overrides_with = "insert_after" + )] insert_after: bool, /// Insert the new change between the target commit(s) and their parents - #[arg(long, short = 'B', visible_alias = "before")] + // + // Repeating this flag is allowed, but has no effect. + #[arg( + long, + short = 'B', + visible_alias = "before", + overrides_with = "insert_before" + )] insert_before: bool, } diff --git a/cli/tests/test_new_command.rs b/cli/tests/test_new_command.rs index db1d965f8..682688a0f 100644 --- a/cli/tests/test_new_command.rs +++ b/cli/tests/test_new_command.rs @@ -125,8 +125,21 @@ fn test_new_insert_after() { ◉ root "###); - let (stdout, stderr) = - test_env.jj_cmd_ok(&repo_path, &["new", "--insert-after", "-m", "G", "B", "D"]); + // --insert-after can be repeated (this does not affect the outcome); --after is + // an alias + let (stdout, stderr) = test_env.jj_cmd_ok( + &repo_path, + &[ + "new", + "--insert-after", + "-m", + "G", + "--after", + "B", + "--after", + "D", + ], + ); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" Rebased 2 descendant commits @@ -172,6 +185,16 @@ fn test_new_insert_after() { ├─╯ ◉ root "###); + + // --after cannot be used with --before + let stderr = test_env.jj_cmd_cli_error(&repo_path, &["new", "--after", "B", "--before", "D"]); + insta::assert_snapshot!(stderr, @r###" + error: the argument '--insert-after' cannot be used with '--insert-before' + + Usage: jj new --insert-after ... + + For more information, try '--help'. + "###); } #[test] @@ -415,7 +438,8 @@ fn setup_before_insertion(test_env: &TestEnvironment, repo_path: &Path) { test_env.jj_cmd_ok(repo_path, &["branch", "create", "D"]); test_env.jj_cmd_ok(repo_path, &["new", "-m", "E", "root()"]); test_env.jj_cmd_ok(repo_path, &["branch", "create", "E"]); - test_env.jj_cmd_ok(repo_path, &["new", "-m", "F", "D", "E"]); + // Any number of -r's is ignored + test_env.jj_cmd_ok(repo_path, &["new", "-m", "F", "-r", "D", "-r", "E"]); test_env.jj_cmd_ok(repo_path, &["branch", "create", "F"]); }