From b1a96c7b36b5fd18e01036ccc065ba7ab37b6589 Mon Sep 17 00:00:00 2001 From: Jason <38263272+jasonalsing@users.noreply.github.com> Date: Tue, 21 Apr 2026 12:46:17 -0500 Subject: [PATCH] fix: only pre-fetch when branch prefix is a known remote name (#958) * fix: only pre-fetch when branch prefix is a known remote name * fix(ui): avoid unused ProjectEntry import --------- Co-authored-by: Bohdan Triapitsyn --- packages/ui/src/components/views/GitView.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/ui/src/components/views/GitView.tsx b/packages/ui/src/components/views/GitView.tsx index b3efeb77..56048061 100644 --- a/packages/ui/src/components/views/GitView.tsx +++ b/packages/ui/src/components/views/GitView.tsx @@ -1653,10 +1653,12 @@ export const GitView: React.FC = () => { const currentBranch = status?.current; + const knownRemoteNames = new Set(effectiveRemotes.map((r) => r.name)); + try { - // If it's a remote branch (contains '/'), fetch latest first + // If it's a remote-tracking branch (prefix matches a known remote), fetch latest first const slashIndex = branch.indexOf('/'); - if (slashIndex > 0) { + if (slashIndex > 0 && knownRemoteNames.has(branch.substring(0, slashIndex))) { const remote = branch.substring(0, slashIndex); const remoteBranch = branch.substring(slashIndex + 1); addOperationLog(`Fetching ${remote}/${remoteBranch}...`, 'running'); @@ -1694,7 +1696,7 @@ export const GitView: React.FC = () => { } // Note: branchOperation is cleared when dialog closes via handleOperationComplete }, - [currentDirectory, git, status, refreshStatusAndBranches, refreshLog, isUncommittedChangesError, persistConflictState, clearConflictState, addOperationLog, updateLastLog, resetOperationLogs] + [currentDirectory, git, status, effectiveRemotes, refreshStatusAndBranches, refreshLog, isUncommittedChangesError, persistConflictState, clearConflictState, addOperationLog, updateLastLog, resetOperationLogs] ); const handleRebase = React.useCallback( @@ -1705,10 +1707,12 @@ export const GitView: React.FC = () => { const currentBranch = status?.current; + const knownRemoteNames = new Set(effectiveRemotes.map((r) => r.name)); + try { - // If it's a remote branch (contains '/'), fetch latest first + // If it's a remote-tracking branch (prefix matches a known remote), fetch latest first const slashIndex = branch.indexOf('/'); - if (slashIndex > 0) { + if (slashIndex > 0 && knownRemoteNames.has(branch.substring(0, slashIndex))) { const remote = branch.substring(0, slashIndex); const remoteBranch = branch.substring(slashIndex + 1); addOperationLog(`Fetching ${remote}/${remoteBranch}...`, 'running'); @@ -1746,7 +1750,7 @@ export const GitView: React.FC = () => { } // Note: branchOperation is cleared when dialog closes via handleOperationComplete }, - [currentDirectory, git, status, refreshStatusAndBranches, refreshLog, isUncommittedChangesError, persistConflictState, clearConflictState, addOperationLog, updateLastLog, resetOperationLogs] + [currentDirectory, git, status, effectiveRemotes, refreshStatusAndBranches, refreshLog, isUncommittedChangesError, persistConflictState, clearConflictState, addOperationLog, updateLastLog, resetOperationLogs] ); const handleAbortConflict = React.useCallback(async () => {