Skip to content

Commit

Permalink
revset: always include non-tracking remote branches in suggestion
Browse files Browse the repository at this point in the history
For the same reason as the previous commit. Non-tracking remote branch
shouldn't be shadowed by a local branch of the same name.
  • Loading branch information
yuja committed Oct 17, 2023
1 parent bcf159c commit 390b320
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/src/revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,9 @@ fn collect_branch_symbols(repo: &dyn Repo, include_synced_remotes: bool) -> Vec<
.remote_refs
.into_iter()
.filter(move |&(_, remote_ref)| {
include_synced_remotes || remote_ref.target != *local_target
include_synced_remotes
|| !remote_ref.is_tracking()
|| remote_ref.target != *local_target
})
.map(move |(remote_name, _)| format!("{name}@{remote_name}"));
local_symbol.into_iter().chain(remote_symbols)
Expand Down
38 changes: 29 additions & 9 deletions lib/tests/test_revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,16 @@ fn test_resolve_symbol_branches() {
let settings = testutils::user_settings();
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let remote_ref = |target| RemoteRef {
let new_remote_ref = |target| RemoteRef {
target,
state: RemoteRefState::Tracking, // doesn't matter
state: RemoteRefState::New,
};
let normal_remote_ref = |id: &CommitId| remote_ref(RefTarget::normal(id.clone()));
let tracking_remote_ref = |target| RemoteRef {
target,
state: RemoteRefState::Tracking,
};
let normal_tracking_remote_ref =
|id: &CommitId| tracking_remote_ref(RefTarget::normal(id.clone()));

let mut tx = repo.start_transaction(&settings, "test");
let mut_repo = tx.mut_repo();
Expand All @@ -398,22 +403,31 @@ fn test_resolve_symbol_branches() {
let commit5 = write_random_commit(mut_repo, &settings);

mut_repo.set_local_branch_target("local", RefTarget::normal(commit1.id().clone()));
mut_repo.set_remote_branch("remote", "origin", normal_remote_ref(commit2.id()));
mut_repo.set_remote_branch("remote", "origin", normal_tracking_remote_ref(commit2.id()));
mut_repo.set_local_branch_target("local-remote", RefTarget::normal(commit3.id().clone()));
mut_repo.set_remote_branch("local-remote", "origin", normal_remote_ref(commit4.id()));
mut_repo.set_remote_branch(
"local-remote",
"origin",
normal_tracking_remote_ref(commit4.id()),
);
mut_repo.set_local_branch_target(
"local-remote@origin", // not a remote branch
RefTarget::normal(commit5.id().clone()),
);
mut_repo.set_remote_branch(
"local-remote",
"mirror",
remote_ref(mut_repo.get_local_branch("local-remote")),
tracking_remote_ref(mut_repo.get_local_branch("local-remote")),
);
mut_repo.set_remote_branch(
"local-remote",
"untracked",
new_remote_ref(mut_repo.get_local_branch("local-remote")),
);
mut_repo.set_remote_branch(
"local-remote",
git::REMOTE_NAME_FOR_LOCAL_GIT_REPO,
remote_ref(mut_repo.get_local_branch("local-remote")),
tracking_remote_ref(mut_repo.get_local_branch("local-remote")),
);

mut_repo.set_local_branch_target(
Expand All @@ -426,7 +440,7 @@ fn test_resolve_symbol_branches() {
mut_repo.set_remote_branch(
"remote-conflicted",
"origin",
remote_ref(RefTarget::from_legacy_form(
tracking_remote_ref(RefTarget::from_legacy_form(
[commit3.id().clone()],
[commit5.id().clone(), commit4.id().clone()],
)),
Expand Down Expand Up @@ -457,6 +471,7 @@ fn test_resolve_symbol_branches() {
name: "remote",
candidates: [
"local-remote@origin",
"local-remote@untracked",
"remote-conflicted@origin",
"remote@origin",
],
Expand Down Expand Up @@ -501,7 +516,9 @@ fn test_resolve_symbol_branches() {

// Typo of local/remote branch name:
// For "local-emote" (without @remote part), "local-remote@mirror"/"@git" aren't
// suggested since they point to the same target as "local-remote".
// suggested since they point to the same target as "local-remote". OTOH,
// "local-remote@untracked" is suggested because non-tracking branch is
// unrelated to the local branch of the same name.
insta::assert_debug_snapshot!(
resolve_symbol(mut_repo, "local-emote").unwrap_err(), @r###"
NoSuchRevision {
Expand All @@ -511,6 +528,7 @@ fn test_resolve_symbol_branches() {
"local-conflicted",
"local-remote",
"local-remote@origin",
"local-remote@untracked",
],
}
"###);
Expand All @@ -524,6 +542,7 @@ fn test_resolve_symbol_branches() {
"local-remote@git",
"local-remote@mirror",
"local-remote@origin",
"local-remote@untracked",
"remote-conflicted@origin",
"remote@origin",
],
Expand All @@ -539,6 +558,7 @@ fn test_resolve_symbol_branches() {
"local-remote@git",
"local-remote@mirror",
"local-remote@origin",
"local-remote@untracked",
"remote-conflicted@origin",
"remote@origin",
],
Expand Down

0 comments on commit 390b320

Please sign in to comment.