Skip to content

Commit 54c15eb

Browse files
committed
fix: add method to get tracking remote for a branch and update pull dialog logic
1 parent d1f3898 commit 54c15eb

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

web/main.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,18 @@ class GitGraphView {
606606
return possibleRemotes.find((remote) => remote !== null && this.gitRemotes.includes(remote)) || this.gitRemotes[0];
607607
}
608608

609+
/**
610+
* Get the remote that the specified branch is tracking.
611+
* @param branchName - The name of the branch to get the tracking remote for
612+
* @returns The name of the remote the branch is tracking, or null if not tracking any remote
613+
*/
614+
private getRemoteForBranch(branchName: string): string | null {
615+
if (!this.gitConfig || !this.gitConfig.branches[branchName]) {
616+
return null;
617+
}
618+
return this.gitConfig.branches[branchName].remote;
619+
}
620+
609621
public getRepoConfig(): Readonly<GG.GitRepoConfig> | null {
610622
return this.gitConfig;
611623
}
@@ -1341,13 +1353,18 @@ class GitGraphView {
13411353
title: 'Pull Branch' + ELLIPSIS,
13421354
visible: visibility.pull && this.gitRemotes.length > 0,
13431355
onClick: () => {
1344-
dialog.showForm('Are you sure you want to update the local branch <b><i>' + escapeHtml(refName) + '</i></b> with the latest changes from <b><i>' + escapeHtml(this.gitRemotes[0] + '/' + refName) + '</i></b>?', [{
1356+
const trackingRemote = this.getRemoteForBranch(refName);
1357+
if (!trackingRemote) {
1358+
dialog.showError('Cannot pull branch <b><i>' + escapeHtml(refName) + '</i></b> because it is not tracking a remote branch. You may need to set an upstream branch first.', 'Pull Branch', null, null);
1359+
return;
1360+
}
1361+
dialog.showForm('Are you sure you want to update the local branch <b><i>' + escapeHtml(refName) + '</i></b> with the latest changes from <b><i>' + escapeHtml(trackingRemote + '/' + refName) + '</i></b>?', [{
13451362
type: DialogInputType.Checkbox,
13461363
name: 'Force Update',
13471364
value: this.config.dialogDefaults.fetchIntoLocalBranch.forceFetch,
13481365
info: 'Force the local branch to be reset to the remote branch (discard local commits).'
13491366
}], 'Yes, update', (values) => {
1350-
runAction({ command: 'fetchIntoLocalBranch', repo: this.currentRepo, remote: this.gitRemotes[0], remoteBranch: refName, localBranch: refName, force: <boolean>values[0] }, 'Updating Branch');
1367+
runAction({ command: 'fetchIntoLocalBranch', repo: this.currentRepo, remote: trackingRemote, remoteBranch: refName, localBranch: refName, force: <boolean>values[0] }, 'Updating Branch');
13511368
}, target);
13521369
}
13531370
}

0 commit comments

Comments
 (0)