Visitar URL original
fix(list): don't give a remote-only default-branch row a self-relatio… · max-sixty/worktrunk@8614958 · GitHub
Skip to content

Commit 8614958

Browse files
fix(list): don't give a remote-only default-branch row a self-relation (#3383)
1 parent a38481b commit 8614958

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎src/commands/list/json_v2.rs‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,12 @@ impl JsonItemV2 {
479479

480480
// The default branch itself gets no relation object. Matching on the
481481
// worktree's main flag alone would miss a branch-only row for the
482-
// default branch, so compare names too.
482+
// default branch, so compare names too. Use the remote-stripped
483+
// `branch` (not `item.branch`) so a remote-only row of the default
484+
// branch (`origin/main`) also matches — otherwise it fails the name
485+
// check and gets a spurious self-referential relation.
483486
let is_default_branch_row = worktree_data.is_some_and(|d| d.is_main)
484-
|| (item.branch.is_some() && item.branch.as_deref() == default_branch);
487+
|| (branch.is_some() && branch.as_deref() == default_branch);
485488
let default_branch = if is_default_branch_row {
486489
Tri::Absent
487490
} else {
@@ -950,6 +953,19 @@ mod tests {
950953
assert!(json.get("default_branch").is_none());
951954
}
952955

956+
#[test]
957+
fn test_remote_default_branch_row_has_no_relation() {
958+
// A remote-only row of the default branch ("origin/main") is still the
959+
// default branch — the name check must compare the remote-stripped
960+
// "main", not the raw "origin/main", so it gets no self-referential
961+
// relation object.
962+
let mut item = item_with("origin/main");
963+
item.kind = ItemKind::Branch(BranchScope::Remote);
964+
let json = to_value(&convert(&item, Collected::default()));
965+
assert_eq!(json["branch"], "main");
966+
assert!(json.get("default_branch").is_none());
967+
}
968+
953969
/// Seed every integration signal to "not integrated" — the state after
954970
/// a full drain with no positive match.
955971
fn load_not_integrated_signals(item: &mut ListItem) {

0 commit comments

Comments
 (0)