From 4a3ba5b8e49d27c42fc10ad51e52239f3f5fb978 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 28 May 2021 22:34:02 -0700 Subject: [PATCH] cli: allow using `--at-op=@` to refer to head operation We already support using "@" to refer to the head operation when doing e.g. `jj op undo -o @`. This patch adds support for `--at-op=@`. It also makes that the default. --- src/commands.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index a45211ea9..fb967ceef 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -140,11 +140,12 @@ fn get_repo(ui: &Ui, matches: &ArgMatches) -> Result, CommandE return Err(CommandError::UserError(message)); } }; - if let Some(op_str) = matches.value_of("at_op") { + let op_str = matches.value_of("at_op").unwrap(); + if op_str == "@" { + Ok(loader.load_at_head()) + } else { let op = resolve_single_op_from_store(loader.op_store(), loader.op_heads_store(), op_str)?; Ok(loader.load_at(&op)) - } else { - Ok(loader.load_at_head()) } } @@ -193,7 +194,7 @@ impl RepoCommandHelper { root_matches: &ArgMatches, ) -> Result { let repo = get_repo(ui, &root_matches)?; - let may_update_working_copy = root_matches.value_of("at_op").is_none(); + let may_update_working_copy = root_matches.value_of("at_op").unwrap() == "@"; Ok(RepoCommandHelper { string_args, settings: ui.settings().clone(), @@ -416,6 +417,8 @@ fn op_arg<'a, 'b>() -> Arg<'a, 'b> { fn resolve_single_op(repo: &ReadonlyRepo, op_str: &str) -> Result { if op_str == "@" { + // Get it from the repo to make sure that it refers to the operation the repo + // was loaded at Ok(repo.operation().clone()) } else { resolve_single_op_from_store(&repo.op_store(), &repo.op_heads_store(), op_str) @@ -821,7 +824,8 @@ fn get_app<'a, 'b>() -> App<'a, 'b> { .long("at-operation") .alias("at-op") .global(true) - .takes_value(true), + .takes_value(true) + .default_value("@"), ) .subcommand(init_command) .subcommand(checkout_command)