From 0ac6df7073e2ec67745b3c5d42d8080a8cc662d7 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 30 Sep 2024 20:08:24 +0900 Subject: [PATCH] revset: make present(unknown@) recover from missing working copy error Missing working-copy commit is similar situation to unknown ref, and should be caught by present(). --- CHANGELOG.md | 4 ++++ lib/src/revset.rs | 6 +++--- lib/tests/test_revset.rs | 13 +++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a4f890a3e..d9466b01f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -107,6 +107,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). * Editing a hidden commit now makes it visible. +* The `present()` revset now suppresses missing working copy error. For example, + `present(@)` evaluates to `none()` if the current workspace has no + working-copy commit. + ## [0.21.0] - 2024-09-04 ### Breaking changes diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 7a20ac5036..927d423348 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -1866,11 +1866,11 @@ fn resolve_symbols( RevsetExpression::Present(candidates) => { resolve_symbols(repo, candidates.clone(), symbol_resolver) .or_else(|err| match err { - RevsetResolutionError::NoSuchRevision { .. } => { + RevsetResolutionError::NoSuchRevision { .. } + | RevsetResolutionError::WorkspaceMissingWorkingCopy { .. } => { Ok(RevsetExpression::none()) } - RevsetResolutionError::WorkspaceMissingWorkingCopy { .. } - | RevsetResolutionError::EmptyString + RevsetResolutionError::EmptyString | RevsetResolutionError::AmbiguousCommitIdPrefix(_) | RevsetResolutionError::AmbiguousChangeIdPrefix(_) | RevsetResolutionError::StoreError(_) diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index b96550cdd8..4dc99b08aa 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -14,6 +14,7 @@ use std::iter; use std::path::Path; +use std::rc::Rc; use assert_matches::assert_matches; use chrono::DateTime; @@ -390,6 +391,18 @@ fn test_resolve_working_copy() { Err(RevsetResolutionError::WorkspaceMissingWorkingCopy { name }) if name == "ws1" ); + // The error can be suppressed by present() + assert_eq!( + Rc::new(RevsetExpression::Present(RevsetExpression::working_copy( + ws1.clone() + ))) + .evaluate_programmatic(mut_repo) + .unwrap() + .iter() + .collect_vec(), + vec![] + ); + // Add some workspaces mut_repo .set_wc_commit(ws1.clone(), commit1.id().clone())