git: Fix pull failing when tracking remote with different branch name (#41768)

Closes #31430

Release Notes:

- Fixed git pull failing when tracking remote with different branch name

Here's a before/after comparison when `dev` branch has upstream set to
`origin/main`:


https://github.com/user-attachments/assets/3a47e736-c7b7-4634-8cd1-aca7300c3a73
This commit is contained in:
Mayank Verma
2025-11-06 05:18:08 +00:00
committed by GitHub
parent 930b489d90
commit 0b1d3d78a4
5 changed files with 24 additions and 22 deletions
+13 -10
View File
@@ -1723,7 +1723,7 @@ impl GitStore {
&mut cx,
);
let branch_name = envelope.payload.branch_name.into();
let branch_name = envelope.payload.branch_name.map(|name| name.into());
let remote_name = envelope.payload.remote_name.into();
let rebase = envelope.payload.rebase;
@@ -4293,7 +4293,7 @@ impl Repository {
pub fn pull(
&mut self,
branch: SharedString,
branch: Option<SharedString>,
remote: SharedString,
rebase: bool,
askpass: AskPassDelegate,
@@ -4303,13 +4303,16 @@ impl Repository {
let askpass_id = util::post_inc(&mut self.latest_askpass_id);
let id = self.id;
let status = if rebase {
Some(format!("git pull --rebase {} {}", remote, branch).into())
} else {
Some(format!("git pull {} {}", remote, branch).into())
};
let mut status = "git pull".to_string();
if rebase {
status.push_str(" --rebase");
}
status.push_str(&format!(" {}", remote));
if let Some(b) = &branch {
status.push_str(&format!(" {}", b));
}
self.send_job(status, move |git_repo, cx| async move {
self.send_job(Some(status.into()), move |git_repo, cx| async move {
match git_repo {
RepositoryState::Local {
backend,
@@ -4318,7 +4321,7 @@ impl Repository {
} => {
backend
.pull(
branch.to_string(),
branch.as_ref().map(|b| b.to_string()),
remote.to_string(),
rebase,
askpass,
@@ -4339,7 +4342,7 @@ impl Repository {
repository_id: id.to_proto(),
askpass_id,
rebase,
branch_name: branch.to_string(),
branch_name: branch.as_ref().map(|b| b.to_string()),
remote_name: remote.to_string(),
})
.await