Skip to content

Commit

Permalink
revset: make present(unknown@) recover from missing working copy error
Browse files Browse the repository at this point in the history
Missing working-copy commit is similar situation to unknown ref, and should
be caught by present().
  • Loading branch information
yuja committed Oct 1, 2024
1 parent 68176d9 commit 0ac6df7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/src/revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_)
Expand Down
13 changes: 13 additions & 0 deletions lib/tests/test_revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::iter;
use std::path::Path;
use std::rc::Rc;

use assert_matches::assert_matches;
use chrono::DateTime;
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 0ac6df7

Please sign in to comment.