fix: make branch updates use latest remote refs

Fetch remote targets before merge or rebase
Prefer remote branch targets over stale local branches
Fix Update copy and branch search input
This commit is contained in:
Bohdan Triapitsyn
2026-05-06 00:32:55 +03:00
parent 8540f51395
commit 32929d592e
7 changed files with 108 additions and 66 deletions
@@ -53,6 +53,7 @@ interface BranchIntegrationSectionProps {
operationLogs?: OperationLogEntry[];
onOperationComplete?: () => void;
mode?: 'dialog' | 'inline';
defaultTargetBranch?: string;
}
export const BranchIntegrationSection: React.FC<BranchIntegrationSectionProps> = ({
@@ -66,6 +67,7 @@ export const BranchIntegrationSection: React.FC<BranchIntegrationSectionProps> =
operationLogs = [],
onOperationComplete,
mode = 'dialog',
defaultTargetBranch,
}) => {
const { t } = useI18n();
const [dialogOpen, setDialogOpen] = React.useState(false);
@@ -94,10 +96,15 @@ export const BranchIntegrationSection: React.FC<BranchIntegrationSectionProps> =
// Filter branches based on search
const filteredLocal = React.useMemo(() => {
const term = branchSearch.toLowerCase();
const filtered = localBranches.filter((b) => b !== currentBranch);
const remoteBranchNames = new Set(
remoteBranches
.map((branch) => branch.slice(branch.indexOf('/') + 1))
.filter(Boolean)
);
const filtered = localBranches.filter((branch) => branch !== currentBranch && !remoteBranchNames.has(branch));
if (!term) return filtered;
return filtered.filter((b) => b.toLowerCase().includes(term));
}, [branchSearch, localBranches, currentBranch]);
}, [branchSearch, localBranches, currentBranch, remoteBranches]);
const filteredRemote = React.useMemo(() => {
const term = branchSearch.toLowerCase();
@@ -105,9 +112,16 @@ export const BranchIntegrationSection: React.FC<BranchIntegrationSectionProps> =
return remoteBranches.filter((b) => b.toLowerCase().includes(term));
}, [branchSearch, remoteBranches]);
const resolveDefaultBranch = React.useCallback(() => {
if (!defaultTargetBranch) return null;
if (remoteBranches.includes(defaultTargetBranch)) return defaultTargetBranch;
if (localBranches.includes(defaultTargetBranch)) return defaultTargetBranch;
return null;
}, [defaultTargetBranch, localBranches, remoteBranches]);
const handleOpenDialog = () => {
setDialogOpen(true);
setSelectedBranch(null);
setSelectedBranch(resolveDefaultBranch());
setOperation('merge');
setBranchSearch('');
};
@@ -158,6 +172,11 @@ export const BranchIntegrationSection: React.FC<BranchIntegrationSectionProps> =
}
}, [branchDropdownOpen]);
React.useEffect(() => {
if (mode !== 'inline' || selectedBranch) return;
setSelectedBranch(resolveDefaultBranch());
}, [mode, resolveDefaultBranch, selectedBranch]);
const renderOperating = () => (
<div className="space-y-3">
<div
@@ -306,6 +325,7 @@ export const BranchIntegrationSection: React.FC<BranchIntegrationSectionProps> =
placeholder={t('gitView.branch.searchPlaceholder')}
value={branchSearch}
onValueChange={setBranchSearch}
onKeyDown={(event) => event.stopPropagation()}
/>
<CommandList className="h-full min-h-0" disableHorizontal>
<CommandEmpty>{t('gitView.branch.empty')}</CommandEmpty>