diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 9d7f4d56e..8387a929d 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -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> { } fn collect_branch_symbols(repo: &dyn Repo, include_synced_remotes: bool) -> Vec { - // 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(); diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index 084ea1c9d..cd1eec20a 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -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()), diff --git a/tests/test_branch_command.rs b/tests/test_branch_command.rs index 259ca91bb..c3a36015a 100644 --- a/tests/test_branch_command.rs +++ b/tests/test_branch_command.rs @@ -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###"