forked from mirrors/jj
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<Commit> or Revset. Let's revisit it later when we get more callers.
This commit is contained in:
parent
f678ba08cf
commit
4e9d35d049
2 changed files with 22 additions and 4 deletions
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue