mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-30 16:19:35 +00:00
cli new: Make -r
, --before
, and --after
repeatable
Repeating these is a no-op. This allows: ```shell jj new -r a -r b # Equivalent to jj new a b jj new --before a --before b # Equivalent to jj new a b --before ``` I keep typing the latter and getting an annoying error.
This commit is contained in:
parent
042d26049c
commit
aa08de30c7
2 changed files with 44 additions and 6 deletions
|
@ -42,7 +42,7 @@ pub(crate) struct NewArgs {
|
|||
#[arg(default_value = "@")]
|
||||
pub(crate) revisions: Vec<RevisionArg>,
|
||||
/// 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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <REVISIONS>...
|
||||
|
||||
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"]);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue