Skip to content

Commit 6374dd0

Browse files
committed
cli: abandon, describe: parse -rREV option properly
I often do "jj log -rREV" to preview the commits to abandon, and it's annoying that I have to remove -r or insert space to "jj abandon ..". The implementation is basically the same as b0c7d0a.
1 parent 5bd669e commit 6374dd0

File tree

5 files changed

+31
-33
lines changed

5 files changed

+31
-33
lines changed

cli/src/commands/abandon.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,17 @@ use crate::ui::Ui;
3636
/// commit. This is true in general; it is not specific to this command.
3737
#[derive(clap::Args, Clone, Debug)]
3838
pub(crate) struct AbandonArgs {
39-
/// The revision(s) to abandon
39+
/// The revision(s) to abandon (default: @)
4040
#[arg(
41-
default_value = "@",
4241
value_name = "REVSETS",
4342
add = ArgValueCandidates::new(complete::mutable_revisions)
4443
)]
45-
revisions: Vec<RevisionArg>,
44+
revisions_pos: Vec<RevisionArg>,
45+
#[arg(short = 'r', hide = true, value_name = "REVSETS")]
46+
revisions_opt: Vec<RevisionArg>,
4647
/// Do not print every abandoned commit on a separate line
4748
#[arg(long, short)]
4849
summary: bool,
49-
/// Ignored (but lets you pass `-r` for consistency with other commands)
50-
#[arg(short = 'r', hide = true, action = clap::ArgAction::Count)]
51-
unused_revision: u8,
5250
/// Do not modify the content of the children of the abandoned commits
5351
#[arg(long)]
5452
restore_descendants: bool,
@@ -61,10 +59,14 @@ pub(crate) fn cmd_abandon(
6159
args: &AbandonArgs,
6260
) -> Result<(), CommandError> {
6361
let mut workspace_command = command.workspace_helper(ui)?;
64-
let to_abandon: Vec<_> = workspace_command
65-
.parse_union_revsets(ui, &args.revisions)?
66-
.evaluate_to_commits()?
67-
.try_collect()?;
62+
let to_abandon: Vec<_> = if !args.revisions_pos.is_empty() || !args.revisions_opt.is_empty() {
63+
workspace_command
64+
.parse_union_revsets(ui, &[&*args.revisions_pos, &*args.revisions_opt].concat())?
65+
} else {
66+
workspace_command.parse_revset(ui, &RevisionArg::AT)?
67+
}
68+
.evaluate_to_commits()?
69+
.try_collect()?;
6870
if to_abandon.is_empty() {
6971
writeln!(ui.status(), "No revisions to abandon.")?;
7072
return Ok(());

cli/src/commands/describe.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ use crate::ui::Ui;
4343
#[derive(clap::Args, Clone, Debug)]
4444
#[command(visible_aliases = &["desc"])]
4545
pub(crate) struct DescribeArgs {
46-
/// The revision(s) whose description to edit
46+
/// The revision(s) whose description to edit (default: @)
4747
#[arg(
48-
default_value = "@",
4948
value_name = "REVSETS",
5049
add = ArgValueCandidates::new(complete::mutable_revisions)
5150
)]
52-
revisions: Vec<RevisionArg>,
53-
/// Ignored (but lets you pass `-r` for consistency with other commands)
54-
#[arg(short = 'r', hide = true, action = clap::ArgAction::Count)]
55-
unused_revision: u8,
51+
revisions_pos: Vec<RevisionArg>,
52+
#[arg(short = 'r', hide = true, value_name = "REVSETS")]
53+
revisions_opt: Vec<RevisionArg>,
5654
/// The change description to use (don't open editor)
5755
///
5856
/// If multiple revisions are specified, the same description will be used
@@ -99,10 +97,14 @@ pub(crate) fn cmd_describe(
9997
args: &DescribeArgs,
10098
) -> Result<(), CommandError> {
10199
let mut workspace_command = command.workspace_helper(ui)?;
102-
let commits: Vec<_> = workspace_command
103-
.parse_union_revsets(ui, &args.revisions)?
104-
.evaluate_to_commits()?
105-
.try_collect()?; // in reverse topological order
100+
let commits: Vec<_> = if !args.revisions_pos.is_empty() || !args.revisions_opt.is_empty() {
101+
workspace_command
102+
.parse_union_revsets(ui, &[&*args.revisions_pos, &*args.revisions_opt].concat())?
103+
} else {
104+
workspace_command.parse_revset(ui, &RevisionArg::AT)?
105+
}
106+
.evaluate_to_commits()?
107+
.try_collect()?; // in reverse topological order
106108
if commits.is_empty() {
107109
writeln!(ui.status(), "No revisions to describe.")?;
108110
return Ok(());

cli/tests/[email protected]

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,7 @@ If a working-copy commit gets abandoned, it will be given a new, empty commit. T
214214
215215
###### **Arguments:**
216216
217-
* `<REVSETS>` — The revision(s) to abandon
218-
219-
Default value: `@`
217+
* `<REVSETS>` — The revision(s) to abandon (default: @)
220218
221219
###### **Options:**
222220
@@ -650,9 +648,7 @@ Starts an editor to let you edit the description of changes. The editor will be
650648
651649
###### **Arguments:**
652650
653-
* `<REVSETS>` — The revision(s) whose description to edit
654-
655-
Default value: `@`
651+
* `<REVSETS>` — The revision(s) whose description to edit (default: @)
656652
657653
###### **Options:**
658654

cli/tests/test_abandon_command.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn test_basics() {
120120

121121
// Test abandoning the same commit twice directly
122122
test_env.jj_cmd_ok(&repo_path, &["undo"]);
123-
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["abandon", "b", "b"]);
123+
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["abandon", "-rb", "b"]);
124124
insta::assert_snapshot!(stdout, @"");
125125
insta::assert_snapshot!(stderr, @r###"
126126
Abandoned commit zsuskuln 1394f625 b | b
@@ -377,10 +377,8 @@ fn test_abandon_restore_descendants() {
377377
std::fs::write(repo_path.join("file"), "baz\n").unwrap();
378378

379379
// Remove the commit containing "bar"
380-
let (stdout, stderr) = test_env.jj_cmd_ok(
381-
&repo_path,
382-
&["abandon", "-r", "@-", "--restore-descendants"],
383-
);
380+
let (stdout, stderr) =
381+
test_env.jj_cmd_ok(&repo_path, &["abandon", "-r@-", "--restore-descendants"]);
384382
insta::assert_snapshot!(stdout, @"");
385383
insta::assert_snapshot!(stderr, @r#"
386384
Abandoned commit rlvkpnrz 225adef1 (no description set)

cli/tests/test_describe_command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn test_describe_multiple_commits() {
204204
// Set the description of multiple commits using `-m` flag
205205
let (stdout, stderr) = test_env.jj_cmd_ok(
206206
&repo_path,
207-
&["describe", "@", "@--", "-m", "description from CLI"],
207+
&["describe", "-r@", "-r@--", "-m", "description from CLI"],
208208
);
209209
insta::assert_snapshot!(stdout, @"");
210210
insta::assert_snapshot!(stderr, @r###"
@@ -224,7 +224,7 @@ fn test_describe_multiple_commits() {
224224
// each commit and doesn't update commits if no changes are made.
225225
// Commit descriptions are edited in topological order
226226
std::fs::write(&edit_script, "dump editor0").unwrap();
227-
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe", "@", "@-"]);
227+
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["describe", "-r@", "@-"]);
228228
insta::assert_snapshot!(stdout, @"");
229229
insta::assert_snapshot!(stderr, @r###"
230230
Nothing changed.

0 commit comments

Comments
 (0)