Skip to content

Commit

Permalink
templater: take non-tracking remote branches as unrelated to local br…
Browse files Browse the repository at this point in the history
…anch

This corresponds to the change I've made for "jj branch list". Non-tracking
remote branches have no relation to local branches.
  • Loading branch information
yuja committed Oct 17, 2023
1 parent eb78ae9 commit c026414
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions cli/src/commit_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,22 +360,26 @@ fn build_branches_index(repo: &dyn Repo) -> RefNamesIndex {
let mut index = RefNamesIndex::default();
for (branch_name, branch_target) in repo.view().branches() {
let local_target = branch_target.local_target;
let mut unsynced_remote_targets = branch_target
.remote_refs
.iter()
.filter(|&&(_, remote_ref)| remote_ref.target != *local_target)
.peekable();
let remote_refs = branch_target.remote_refs;
let unsynced_remote_refs = remote_refs.iter().copied().filter(|&(_, remote_ref)| {
!remote_ref.is_tracking() || remote_ref.target != *local_target
});
let has_unsynced_tracking_refs = || {
remote_refs.iter().any(|&(_, remote_ref)| {
remote_ref.is_tracking() && remote_ref.target != *local_target
})
};
if local_target.is_present() {
let decorated_name = if local_target.has_conflict() {
format!("{branch_name}??")
} else if unsynced_remote_targets.peek().is_some() {
} else if has_unsynced_tracking_refs() {
format!("{branch_name}*")
} else {
branch_name.to_owned()
};
index.insert(local_target.added_ids(), decorated_name);
}
for &(remote_name, remote_ref) in unsynced_remote_targets {
for (remote_name, remote_ref) in unsynced_remote_refs {
let decorated_name = if remote_ref.target.has_conflict() {
format!("{branch_name}@{remote_name}?")
} else {
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_branch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ fn test_branch_track_untrack() {
main: sptzoqmo 7b33f629 commit 1
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
◉ feature1 feature2@origin main 7b33f6295eda
◉ feature1 feature1@origin feature2@origin main 7b33f6295eda
│ @ 230dd059e1b0
├─╯
◉ 000000000000
Expand All @@ -586,7 +586,7 @@ fn test_branch_track_untrack() {
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
◉ feature1@origin feature2@origin main 40dabdaf4abe
│ ◉ feature1* 7b33f6295eda
│ ◉ feature1 7b33f6295eda
├─╯
│ @ 230dd059e1b0
├─╯
Expand Down Expand Up @@ -619,7 +619,7 @@ fn test_branch_track_untrack() {
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
◉ feature1@origin feature2@origin feature3 main 3f0f86fa0e57
│ ◉ feature1* 7b33f6295eda
│ ◉ feature1 7b33f6295eda
├─╯
│ @ 230dd059e1b0
├─╯
Expand Down

0 comments on commit c026414

Please sign in to comment.