From 99c42c5a8f2cd4d302a2728c11ca72d067e6058e Mon Sep 17 00:00:00 2001 From: Noah Mayr Date: Mon, 1 Apr 2024 18:01:12 +0200 Subject: [PATCH] cli: add better error message when immutable_heads() cannot be resolved --- cli/src/cli_util.rs | 24 +++++++++++++++++++++--- docs/contributing.md | 2 +- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 71af456307e..0095c7ee5ad 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -53,7 +53,7 @@ use jj_lib::repo::{ use jj_lib::repo_path::{FsPathParseError, RepoPath, RepoPathBuf}; use jj_lib::revset::{ RevsetAliasesMap, RevsetCommitRef, RevsetExpression, RevsetFilterPredicate, RevsetIteratorExt, - RevsetParseContext, RevsetWorkspaceContext, + RevsetParseContext, RevsetResolutionError, RevsetWorkspaceContext, }; use jj_lib::rewrite::restore_tree; use jj_lib::settings::{ConfigResultExt as _, UserSettings}; @@ -88,7 +88,7 @@ use crate::git_util::{ }; use crate::merge_tools::{DiffEditor, MergeEditor, MergeToolConfigError}; use crate::operation_templater::OperationTemplateLanguageExtension; -use crate::revset_util::RevsetExpressionEvaluator; +use crate::revset_util::{RevsetExpressionEvaluator, UserRevsetEvaluationError}; use crate::template_builder::TemplateLanguage; use crate::template_parser::TemplateAliasesMap; use crate::templater::{PropertyPlaceholder, TemplateRenderer}; @@ -1012,7 +1012,25 @@ impl WorkspaceCommandHelper { let immutable = revset_util::parse_immutable_expression(&self.revset_parse_context())?; let mut expression = self.attach_revset_evaluator(immutable)?; expression.intersect_with(&to_rewrite_revset); - if let Some(commit_id) = expression.evaluate_to_commit_ids()?.next() { + if let Some(commit_id) = expression + .evaluate_to_commit_ids() + .map_err(|e| { + let UserRevsetEvaluationError::Resolution(RevsetResolutionError::NoSuchRevision { + name, + candidates: _, + }) = e + else { + return e.into(); + }; + user_error(format!( + "The expression '{}' of immutable_heads() could not be resolved, if you \ + configured specific branch names consider wrapping them with 'present()' or \ + using the functions 'branches()' / 'remote_branches()'.", + name + )) + })? + .next() + { let error = if &commit_id == self.repo().store().root_commit_id() { user_error(format!( "The root commit {} is immutable", diff --git a/docs/contributing.md b/docs/contributing.md index c4c75c64480..d1df5da243c 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -114,7 +114,7 @@ You will probably also want to make the `gh-pages` branch immutable (and thereby hidden from the default `jj log` output) by running the following in your repo: ```shell -jj config set --repo "revset-aliases.immutable_heads()" "main@origin | gh-pages@origin" +jj config set --repo "revset-aliases.immutable_heads()" 'remote_branches(exact:"main") | remote_branches(exact:"origin")' ``` ### Summary