mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-28 15:26:25 +00:00
revset: fix crash on "log --at-op 00000000 -r 'root()'"
Spotted while refactoring IdPrefixContext.
This commit is contained in:
parent
0a8d8dad67
commit
db226d9f64
2 changed files with 29 additions and 1 deletions
|
@ -1798,7 +1798,18 @@ fn resolve_commit_ref(
|
||||||
Ok(wc_commits)
|
Ok(wc_commits)
|
||||||
}
|
}
|
||||||
RevsetCommitRef::VisibleHeads => Ok(repo.view().heads().iter().cloned().collect_vec()),
|
RevsetCommitRef::VisibleHeads => Ok(repo.view().heads().iter().cloned().collect_vec()),
|
||||||
RevsetCommitRef::Root => Ok(vec![repo.store().root_commit_id().clone()]),
|
RevsetCommitRef::Root => {
|
||||||
|
let commit_id = repo.store().root_commit_id();
|
||||||
|
if repo.index().has_id(commit_id) {
|
||||||
|
Ok(vec![commit_id.clone()])
|
||||||
|
} else {
|
||||||
|
// The root commit doesn't exist at the root operation.
|
||||||
|
Err(RevsetResolutionError::NoSuchRevision {
|
||||||
|
name: "root()".to_owned(),
|
||||||
|
candidates: vec![],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
RevsetCommitRef::Bookmarks(pattern) => {
|
RevsetCommitRef::Bookmarks(pattern) => {
|
||||||
let commit_ids = repo
|
let commit_ids = repo
|
||||||
.view()
|
.view()
|
||||||
|
|
|
@ -34,6 +34,7 @@ use jj_lib::op_store::RefTarget;
|
||||||
use jj_lib::op_store::RemoteRef;
|
use jj_lib::op_store::RemoteRef;
|
||||||
use jj_lib::op_store::RemoteRefState;
|
use jj_lib::op_store::RemoteRefState;
|
||||||
use jj_lib::op_store::WorkspaceId;
|
use jj_lib::op_store::WorkspaceId;
|
||||||
|
use jj_lib::operation::Operation;
|
||||||
use jj_lib::repo::Repo;
|
use jj_lib::repo::Repo;
|
||||||
use jj_lib::repo_path::RepoPath;
|
use jj_lib::repo_path::RepoPath;
|
||||||
use jj_lib::repo_path::RepoPathUiConverter;
|
use jj_lib::repo_path::RepoPathUiConverter;
|
||||||
|
@ -942,6 +943,14 @@ fn test_evaluate_expression_root_and_checkout() {
|
||||||
let test_workspace = TestWorkspace::init(&settings);
|
let test_workspace = TestWorkspace::init(&settings);
|
||||||
let repo = &test_workspace.repo;
|
let repo = &test_workspace.repo;
|
||||||
|
|
||||||
|
let root_operation = {
|
||||||
|
let op_store = repo.op_store();
|
||||||
|
let id = op_store.root_operation_id();
|
||||||
|
let data = op_store.read_operation(id).unwrap();
|
||||||
|
Operation::new(op_store.clone(), id.clone(), data)
|
||||||
|
};
|
||||||
|
let root_repo = repo.reload_at(&root_operation).unwrap();
|
||||||
|
|
||||||
let mut tx = repo.start_transaction(&settings);
|
let mut tx = repo.start_transaction(&settings);
|
||||||
let mut_repo = tx.repo_mut();
|
let mut_repo = tx.repo_mut();
|
||||||
|
|
||||||
|
@ -954,6 +963,14 @@ fn test_evaluate_expression_root_and_checkout() {
|
||||||
vec![root_commit.id().clone()]
|
vec![root_commit.id().clone()]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// but not in the root operation. It might be okay to pretend that the root
|
||||||
|
// commit exists in the root operation, but queries like "root()" shouldn't
|
||||||
|
// panic in any case.
|
||||||
|
assert_matches!(
|
||||||
|
resolve_symbol(root_repo.as_ref(), "root()"),
|
||||||
|
Err(RevsetResolutionError::NoSuchRevision { .. })
|
||||||
|
);
|
||||||
|
|
||||||
// Can find the current working-copy commit
|
// Can find the current working-copy commit
|
||||||
mut_repo
|
mut_repo
|
||||||
.set_wc_commit(WorkspaceId::default(), commit1.id().clone())
|
.set_wc_commit(WorkspaceId::default(), commit1.id().clone())
|
||||||
|
|
Loading…
Reference in a new issue