diff --git a/crates/workspace/src/views/pull_requests/new.rs b/crates/workspace/src/views/pull_requests/new.rs index 4eac45a..5a5f238 100644 --- a/crates/workspace/src/views/pull_requests/new.rs +++ b/crates/workspace/src/views/pull_requests/new.rs @@ -562,9 +562,6 @@ impl NewPullRequestView { let task: gpui::Task> = cx.spawn_in(window, async move |this, cx| { - // The fork and base must share history for a merge-base to exist. - // The target's mirror is the object store both sides land in. - // `ensure_repo_mirror` fetches `origin` when the mirror already exists. let result = cx .background_spawn({ let base = base.clone(); @@ -575,10 +572,10 @@ impl NewPullRequestView { async move { ensure_repo_mirror(&base, &base_clone_urls)?; - // Prune stale imports of any fork. - // Then import this fork's heads under its namespace. + // Prune stale imports of any fork. Then import this fork's heads under its namespace. delete_refs_with_prefix(&mirror_path, "refs/fork")?; + // Fetch the fork's refs and import them under the fork's namespace. fetch_repo_refs( &mirror_path, &clone_urls, @@ -658,8 +655,6 @@ impl NewPullRequestView { let (base_branches, compare_branches) = match result { Ok(branches) => branches, Err(error) => { - // Keep the previous source, if any. - // The error shows inline next to the compare bar. self.error = Some(format!("Could not compare against the fork: {error}").into()); cx.notify(); return; @@ -673,8 +668,7 @@ impl NewPullRequestView { } if base_branches.is_empty() { - self.error = - Some("Could not list the target repository's branches; try again later".into()); + self.error = Some("Could not list the target repository's branches.".into()); cx.notify(); return; } @@ -687,11 +681,8 @@ impl NewPullRequestView { .map(SharedString::from) .collect(); - // Base defaults to the announced HEAD branch when the mirror has it. - // Otherwise `main`, then the first branch. - // The fork's `main` is the compare default, else the first branch. - // A refresh keeps the previous selection when the branch still exists. let announced = self.store.read(cx).head.clone(); + let contains = |name: &str, list: &[SharedString]| list.iter().any(|branch| branch.as_ref() == name); @@ -790,16 +781,19 @@ impl NewPullRequestView { "{base_name} and {compare_name} share no common ancestor" ) })?; + let commits = worktree_commit_range_commits( Path::new(&repo_path), &merge_base, &compare, )?; + let diff = worktree_commit_range_diff( Path::new(&repo_path), &merge_base, &compare, )?; + Ok::<_, anyhow::Error>((merge_base, commits, diff)) } }) @@ -923,6 +917,7 @@ impl NewPullRequestView { let Some(repo_path) = self.work_path() else { return; }; + let Some(dock_area) = self.dock_area.upgrade() else { return; };