Skip to content

Commit 2bb49cc

Browse files
committed
fix some bugs
1 parent a849e5d commit 2bb49cc

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/git2_ops.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,21 @@ impl GitRepo {
9393
branch: &str,
9494
) -> Result<GitBranchStatus> {
9595
let exists = self.branch_exists(branch);
96+
97+
// Resolve parent branch - use origin/<parent> if local doesn't exist
9698
let parent_branch = match parent_branch {
97-
Some(parent_branch) => parent_branch.to_string(),
99+
Some(parent_branch) => {
100+
if self.branch_exists(parent_branch) {
101+
parent_branch.to_string()
102+
} else {
103+
let remote_parent = format!("origin/{}", parent_branch);
104+
if self.ref_exists(&remote_parent) {
105+
remote_parent
106+
} else {
107+
parent_branch.to_string()
108+
}
109+
}
110+
}
98111
None => self.remote_main(DEFAULT_REMOTE)?,
99112
};
100113

@@ -112,8 +125,16 @@ impl GitRepo {
112125
});
113126
(sha, is_descendent, upstream_status)
114127
} else {
115-
// Branch doesn't exist - use placeholder values
116-
(String::new(), false, None)
128+
// Local branch doesn't exist - try using origin/<branch> instead
129+
let remote_ref = format!("origin/{}", branch);
130+
if self.ref_exists(&remote_ref) {
131+
let sha = self.sha(&remote_ref).unwrap_or_default();
132+
let is_descendent = self.is_ancestor(&parent_branch, &remote_ref).unwrap_or(false);
133+
(sha, is_descendent, None)
134+
} else {
135+
// Neither local nor remote exists - use placeholder values
136+
(String::new(), false, None)
137+
}
117138
};
118139

119140
Ok(GitBranchStatus {

src/state.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,9 @@ fn cleanup_tree_recursive(
946946
let mut indices_to_remove = Vec::new();
947947

948948
for (index, child) in branch.branches.iter().enumerate() {
949-
if !git_branch_exists(git_repo, &child.name) {
950-
// This branch doesn't exist locally, mark it for removal
949+
let remote_ref = format!("origin/{}", child.name);
950+
if !git_branch_exists(git_repo, &child.name) && !git_repo.ref_exists(&remote_ref) {
951+
// This branch doesn't exist locally or on remote, mark it for removal
951952
removed_branches.push(child.name.clone());
952953

953954
// Collect its children to be adopted by the current branch

0 commit comments

Comments
 (0)