From 4e9d35d04925c1f5a9cd41c20b5b2e1c42b00a49 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 17 Mar 2024 12:18:09 +0900 Subject: [PATCH] cli: make "abandon" not fail with empty revset This command belongs to the same category as "duplicate". We might want a plural version of resolve_revset(), but I'm not sure whether it should return Vec or Revset. Let's revisit it later when we get more callers. --- cli/src/commands/abandon.rs | 19 ++++++++++++++++--- cli/tests/test_abandon_command.rs | 7 ++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cli/src/commands/abandon.rs b/cli/src/commands/abandon.rs index d795e3de2..06e15369b 100644 --- a/cli/src/commands/abandon.rs +++ b/cli/src/commands/abandon.rs @@ -14,10 +14,13 @@ use std::io::Write; +use itertools::Itertools as _; use jj_lib::object_id::ObjectId; +use jj_lib::repo::Repo as _; +use jj_lib::revset::RevsetIteratorExt as _; use tracing::instrument; -use crate::cli_util::{resolve_multiple_nonempty_revsets, CommandHelper, RevisionArg}; +use crate::cli_util::{CommandHelper, RevisionArg}; use crate::command_error::CommandError; use crate::ui::Ui; @@ -49,8 +52,18 @@ pub(crate) fn cmd_abandon( args: &AbandonArgs, ) -> Result<(), CommandError> { let mut workspace_command = command.workspace_helper(ui)?; - let to_abandon = resolve_multiple_nonempty_revsets(&args.revisions, &workspace_command)?; - workspace_command.check_rewritable(to_abandon.iter())?; + let to_abandon: Vec<_> = { + let repo = workspace_command.repo(); + let expression = workspace_command.parse_union_revsets(&args.revisions)?; + let revset = workspace_command.evaluate_revset(expression)?; + revset.iter().commits(repo.store()).try_collect()? + }; + if to_abandon.is_empty() { + writeln!(ui.stderr(), "No revisions to abandon.")?; + return Ok(()); + } + workspace_command.check_rewritable(&to_abandon)?; + let mut tx = workspace_command.start_transaction(); for commit in &to_abandon { tx.mut_repo().record_abandoned_commit(commit.id().clone()); diff --git a/cli/tests/test_abandon_command.rs b/cli/tests/test_abandon_command.rs index 05fe7855e..370e0fbd5 100644 --- a/cli/tests/test_abandon_command.rs +++ b/cli/tests/test_abandon_command.rs @@ -150,6 +150,11 @@ fn test_basics() { ├─╯ ◉ [zzz] a b e?? "###); + + let (_stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["abandon", "none()"]); + insta::assert_snapshot!(stderr, @r###" + No revisions to abandon. + "###); } // This behavior illustrates https://github.com/martinvonz/jj/issues/2600. @@ -263,8 +268,8 @@ fn test_bug_2600() { insta::assert_snapshot!(stdout, @""); insta::assert_snapshot!(stderr, @r###" Abandoned the following commits: - royxmykx 98f3b9ba a | a vruxwmqv 8c0dced0 b | b + royxmykx 98f3b9ba a | a Rebased 1 descendant commits onto parents of abandoned commits Working copy now at: znkkpsqq 84fac1f8 c | c Parent commit : zsuskuln 73c929fc a b base | base