diff --git a/cli/src/commands/abandon.rs b/cli/src/commands/abandon.rs index 9b02cedc69..7ff6239379 100644 --- a/cli/src/commands/abandon.rs +++ b/cli/src/commands/abandon.rs @@ -36,19 +36,17 @@ use crate::ui::Ui; /// commit. This is true in general; it is not specific to this command. #[derive(clap::Args, Clone, Debug)] pub(crate) struct AbandonArgs { - /// The revision(s) to abandon + /// The revision(s) to abandon (default: @) #[arg( - default_value = "@", value_name = "REVSETS", add = ArgValueCandidates::new(complete::mutable_revisions) )] - revisions: Vec, + revisions_pos: Vec, + #[arg(short = 'r', hide = true, value_name = "REVSETS")] + revisions_opt: Vec, /// Do not print every abandoned commit on a separate line #[arg(long, short)] summary: bool, - /// Ignored (but lets you pass `-r` for consistency with other commands) - #[arg(short = 'r', hide = true, action = clap::ArgAction::Count)] - unused_revision: u8, /// Do not modify the content of the children of the abandoned commits #[arg(long)] restore_descendants: bool, @@ -61,10 +59,14 @@ pub(crate) fn cmd_abandon( args: &AbandonArgs, ) -> Result<(), CommandError> { let mut workspace_command = command.workspace_helper(ui)?; - let to_abandon: Vec<_> = workspace_command - .parse_union_revsets(ui, &args.revisions)? - .evaluate_to_commits()? - .try_collect()?; + let to_abandon: Vec<_> = if !args.revisions_pos.is_empty() || !args.revisions_opt.is_empty() { + workspace_command + .parse_union_revsets(ui, &[&*args.revisions_pos, &*args.revisions_opt].concat())? + } else { + workspace_command.parse_revset(ui, &RevisionArg::AT)? + } + .evaluate_to_commits()? + .try_collect()?; if to_abandon.is_empty() { writeln!(ui.status(), "No revisions to abandon.")?; return Ok(()); diff --git a/cli/src/commands/describe.rs b/cli/src/commands/describe.rs index f4f1fb36e7..25e3ddef79 100644 --- a/cli/src/commands/describe.rs +++ b/cli/src/commands/describe.rs @@ -43,16 +43,14 @@ use crate::ui::Ui; #[derive(clap::Args, Clone, Debug)] #[command(visible_aliases = &["desc"])] pub(crate) struct DescribeArgs { - /// The revision(s) whose description to edit + /// The revision(s) whose description to edit (default: @) #[arg( - default_value = "@", value_name = "REVSETS", add = ArgValueCandidates::new(complete::mutable_revisions) )] - revisions: Vec, - /// Ignored (but lets you pass `-r` for consistency with other commands) - #[arg(short = 'r', hide = true, action = clap::ArgAction::Count)] - unused_revision: u8, + revisions_pos: Vec, + #[arg(short = 'r', hide = true, value_name = "REVSETS")] + revisions_opt: Vec, /// The change description to use (don't open editor) /// /// If multiple revisions are specified, the same description will be used @@ -99,10 +97,14 @@ pub(crate) fn cmd_describe( args: &DescribeArgs, ) -> Result<(), CommandError> { let mut workspace_command = command.workspace_helper(ui)?; - let commits: Vec<_> = workspace_command - .parse_union_revsets(ui, &args.revisions)? - .evaluate_to_commits()? - .try_collect()?; // in reverse topological order + let commits: Vec<_> = if !args.revisions_pos.is_empty() || !args.revisions_opt.is_empty() { + workspace_command + .parse_union_revsets(ui, &[&*args.revisions_pos, &*args.revisions_opt].concat())? + } else { + workspace_command.parse_revset(ui, &RevisionArg::AT)? + } + .evaluate_to_commits()? + .try_collect()?; // in reverse topological order if commits.is_empty() { writeln!(ui.status(), "No revisions to describe.")?; return Ok(()); diff --git a/cli/tests/cli-reference@.md.snap b/cli/tests/cli-reference@.md.snap index d9fc70a9cc..ea7cbd178c 100644 --- a/cli/tests/cli-reference@.md.snap +++ b/cli/tests/cli-reference@.md.snap @@ -214,9 +214,7 @@ If a working-copy commit gets abandoned, it will be given a new, empty commit. T ###### **Arguments:** -* `` — The revision(s) to abandon - - Default value: `@` +* `` — The revision(s) to abandon (default: @) ###### **Options:** @@ -650,9 +648,7 @@ Starts an editor to let you edit the description of changes. The editor will be ###### **Arguments:** -* `` — The revision(s) whose description to edit - - Default value: `@` +* `` — The revision(s) whose description to edit (default: @) ###### **Options:** diff --git a/cli/tests/test_abandon_command.rs b/cli/tests/test_abandon_command.rs index cb13dbe062..58c9089cc9 100644 --- a/cli/tests/test_abandon_command.rs +++ b/cli/tests/test_abandon_command.rs @@ -120,7 +120,7 @@ fn test_basics() { // Test abandoning the same commit twice directly test_env.jj_cmd_ok(&repo_path, &["undo"]); - let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["abandon", "b", "b"]); + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["abandon", "-rb", "b"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" Abandoned commit zsuskuln 1394f625 b | b @@ -377,10 +377,8 @@ fn test_abandon_restore_descendants() { std::fs::write(repo_path.join("file"), "baz\n").unwrap(); // Remove the commit containing "bar" - let (stdout, stderr) = test_env.jj_cmd_ok( - &repo_path, - &["abandon", "-r", "@-", "--restore-descendants"], - ); + let (stdout, stderr) = + test_env.jj_cmd_ok(&repo_path, &["abandon", "-r@-", "--restore-descendants"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r#" Abandoned commit rlvkpnrz 225adef1 (no description set) diff --git a/cli/tests/test_describe_command.rs b/cli/tests/test_describe_command.rs index b5f9237467..8d3f7c920e 100644 --- a/cli/tests/test_describe_command.rs +++ b/cli/tests/test_describe_command.rs @@ -204,7 +204,7 @@ fn test_describe_multiple_commits() { // Set the description of multiple commits using `-m` flag let (stdout, stderr) = test_env.jj_cmd_ok( &repo_path, - &["describe", "@", "@--", "-m", "description from CLI"], + &["describe", "-r@", "-r@--", "-m", "description from CLI"], ); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" @@ -224,7 +224,7 @@ fn test_describe_multiple_commits() { // each commit and doesn't update commits if no changes are made. // Commit descriptions are edited in topological order std::fs::write(&edit_script, "dump editor0").unwrap(); - let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe", "@", "@-"]); + let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe", "-r@", "@-"]); insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" Nothing changed.