mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-05 19:14:43 +00:00
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 b0c7d0a7e2
.
This commit is contained in:
parent
5bd669e892
commit
6374dd0cfe
5 changed files with 31 additions and 33 deletions
|
@ -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,
|
||||
|
@ -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(());
|
||||
|
|
|
@ -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
|
||||
|
@ -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(());
|
||||
|
|
|
@ -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:**
|
||||
|
||||
|
@ -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:**
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue