revset: include pseudo @git remote in suggestion

Since collect_branch_symbols() doesn't have to be fast, I made it simply
build a new branches map.
This commit is contained in:
Yuya Nishihara 2023-07-09 18:17:48 +09:00
parent 528f6e23c1
commit 9aa308fb4a
3 changed files with 29 additions and 12 deletions

View file

@ -31,7 +31,7 @@ use thiserror::Error;
use crate::backend::{BackendError, BackendResult, ChangeId, CommitId, ObjectId};
use crate::commit::Commit;
use crate::git::get_local_git_tracking_branch;
use crate::git::{self, get_local_git_tracking_branch};
use crate::hex_util::to_forward_hex;
use crate::index::{HexPrefix, PrefixResolution};
use crate::op_store::WorkspaceId;
@ -1660,9 +1660,8 @@ fn resolve_branch(repo: &dyn Repo, symbol: &str) -> Option<Vec<CommitId>> {
}
fn collect_branch_symbols(repo: &dyn Repo, include_synced_remotes: bool) -> Vec<String> {
// TODO: include "@git" branches
repo.view()
.branches()
let (all_branches, _) = git::build_unified_branches_map(repo.view());
all_branches
.iter()
.flat_map(|(name, branch_target)| {
let local_target = branch_target.local_target.as_ref();

View file

@ -445,6 +445,10 @@ fn test_resolve_symbol_branches() {
"mirror".to_owned(),
mut_repo.get_local_branch("local-remote").unwrap(),
);
mut_repo.set_git_ref(
"refs/heads/local-remote".to_owned(),
mut_repo.get_local_branch("local-remote").unwrap(),
);
mut_repo.set_local_branch(
"local-conflicted".to_owned(),
@ -473,6 +477,7 @@ fn test_resolve_symbol_branches() {
name: "local@origin",
candidates: [
"local",
"local-remote@git",
"local-remote@origin",
"remote@origin",
],
@ -496,7 +501,7 @@ fn test_resolve_symbol_branches() {
vec![commit2.id().clone()],
);
// Local/remote
// Local/remote/git
assert_eq!(
resolve_symbol(mut_repo, "local-remote", None).unwrap(),
vec![commit3.id().clone()],
@ -509,6 +514,10 @@ fn test_resolve_symbol_branches() {
resolve_symbol(mut_repo, "local-remote@mirror", None).unwrap(),
vec![commit3.id().clone()],
);
assert_eq!(
resolve_symbol(mut_repo, "local-remote@git", None).unwrap(),
vec![commit3.id().clone()],
);
// Conflicted
assert_eq!(
@ -521,8 +530,8 @@ fn test_resolve_symbol_branches() {
);
// Typo of local/remote branch name:
// For "local-emote" (without @remote part), "local-remote@mirror" isn't
// suggested since it points to the same target as "local-remote".
// For "local-emote" (without @remote part), "local-remote@mirror"/"@git" aren't
// suggested since they point to the same target as "local-remote".
insta::assert_debug_snapshot!(
resolve_symbol(mut_repo, "local-emote", None).unwrap_err(), @r###"
NoSuchRevision {
@ -542,6 +551,7 @@ fn test_resolve_symbol_branches() {
candidates: [
"local",
"local-remote",
"local-remote@git",
"local-remote@mirror",
"local-remote@origin",
"remote-conflicted@origin",
@ -556,6 +566,7 @@ fn test_resolve_symbol_branches() {
candidates: [
"local",
"local-remote",
"local-remote@git",
"local-remote@mirror",
"local-remote@origin",
"remote-conflicted@origin",
@ -672,11 +683,17 @@ fn test_resolve_symbol_git_refs() {
RefTarget::Normal(commit5.id().clone()),
);
// branch alone is not recognized
assert_matches!(
resolve_symbol(mut_repo, "branch", None),
Err(RevsetResolutionError::NoSuchRevision{name, candidates})
if name == "branch" && candidates.is_empty()
);
insta::assert_debug_snapshot!(
resolve_symbol(mut_repo, "branch", None).unwrap_err(), @r###"
NoSuchRevision {
name: "branch",
candidates: [
"branch1@git",
"branch2@git",
"branch@git",
],
}
"###);
mut_repo.set_git_ref(
"refs/tags/branch".to_string(),
RefTarget::Normal(commit4.id().clone()),

View file

@ -247,6 +247,7 @@ fn test_branch_forget_export() {
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r=foo", "--no-graph"]);
insta::assert_snapshot!(stderr, @r###"
Error: Revision "foo" doesn't exist
Hint: Did you mean "foo@git"?
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r=foo@git", "--no-graph"]);
insta::assert_snapshot!(stdout, @r###"