Skip to content

Commit

Permalink
cli: abandon, describe: parse -rREV option properly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yuja committed Dec 23, 2024
1 parent 5bd669e commit 6374dd0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
22 changes: 12 additions & 10 deletions cli/src/commands/abandon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RevisionArg>,
revisions_pos: Vec<RevisionArg>,
#[arg(short = 'r', hide = true, value_name = "REVSETS")]
revisions_opt: Vec<RevisionArg>,
/// 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,
Expand All @@ -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(());
Expand Down
22 changes: 12 additions & 10 deletions cli/src/commands/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RevisionArg>,
/// 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<RevisionArg>,
#[arg(short = 'r', hide = true, value_name = "REVSETS")]
revisions_opt: Vec<RevisionArg>,
/// The change description to use (don't open editor)
///
/// If multiple revisions are specified, the same description will be used
Expand Down Expand Up @@ -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(());
Expand Down
8 changes: 2 additions & 6 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ If a working-copy commit gets abandoned, it will be given a new, empty commit. T
###### **Arguments:**
* `<REVSETS>` — The revision(s) to abandon
Default value: `@`
* `<REVSETS>` — The revision(s) to abandon (default: @)
###### **Options:**
Expand Down Expand Up @@ -650,9 +648,7 @@ Starts an editor to let you edit the description of changes. The editor will be
###### **Arguments:**
* `<REVSETS>` — The revision(s) whose description to edit
Default value: `@`
* `<REVSETS>` — The revision(s) whose description to edit (default: @)
###### **Options:**
Expand Down
8 changes: 3 additions & 5 deletions cli/tests/test_abandon_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/test_describe_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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###"
Expand All @@ -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.
Expand Down

0 comments on commit 6374dd0

Please sign in to comment.