mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-05 09:33:07 +00:00
fix: Include remote branches in PR base selection even when local branch exists
The branch listing logic now correctly shows remote branches (e.g., "origin/main") even if a local branch with the same base name exists, since users need remote branches as PR base targets. Also extracted duplicate state reset logic in create-pr-dialog into a reusable function.
This commit is contained in:
@@ -92,12 +92,12 @@ export function createListBranchesHandler() {
|
|||||||
// Skip HEAD pointers like "origin/HEAD"
|
// Skip HEAD pointers like "origin/HEAD"
|
||||||
if (cleanName.includes('/HEAD')) return;
|
if (cleanName.includes('/HEAD')) return;
|
||||||
|
|
||||||
// Extract the branch name without the remote prefix for deduplication
|
// Only add remote branches if a branch with the exact same name isn't already
|
||||||
// e.g., "origin/main" -> "main"
|
// in the list. This avoids duplicates if a local branch is named like a remote one.
|
||||||
const branchNameWithoutRemote = cleanName.replace(/^[^/]+\//, '');
|
// Note: We intentionally include remote branches even when a local branch with the
|
||||||
|
// same base name exists (e.g., show "origin/main" even if local "main" exists),
|
||||||
// Only add remote branches that don't exist locally (to avoid duplicates)
|
// since users need to select remote branches as PR base targets.
|
||||||
if (!localBranchNames.has(branchNameWithoutRemote)) {
|
if (!localBranchNames.has(cleanName)) {
|
||||||
branches.push({
|
branches.push({
|
||||||
name: cleanName, // Keep full name like "origin/main"
|
name: cleanName, // Keep full name like "origin/main"
|
||||||
isCurrent: false,
|
isCurrent: false,
|
||||||
|
|||||||
@@ -59,6 +59,21 @@ export function CreatePRDialog({
|
|||||||
// Track whether an operation completed that warrants a refresh
|
// Track whether an operation completed that warrants a refresh
|
||||||
const operationCompletedRef = useRef(false);
|
const operationCompletedRef = useRef(false);
|
||||||
|
|
||||||
|
// Common state reset function to avoid duplication
|
||||||
|
const resetState = useCallback(() => {
|
||||||
|
setTitle('');
|
||||||
|
setBody('');
|
||||||
|
setCommitMessage('');
|
||||||
|
setBaseBranch(defaultBaseBranch);
|
||||||
|
setIsDraft(false);
|
||||||
|
setError(null);
|
||||||
|
setPrUrl(null);
|
||||||
|
setBrowserUrl(null);
|
||||||
|
setShowBrowserFallback(false);
|
||||||
|
operationCompletedRef.current = false;
|
||||||
|
setBranches([]);
|
||||||
|
}, [defaultBaseBranch]);
|
||||||
|
|
||||||
// Fetch branches for autocomplete
|
// Fetch branches for autocomplete
|
||||||
const fetchBranches = useCallback(async () => {
|
const fetchBranches = useCallback(async () => {
|
||||||
if (!worktree?.path) return;
|
if (!worktree?.path) return;
|
||||||
@@ -87,39 +102,13 @@ export function CreatePRDialog({
|
|||||||
|
|
||||||
// Reset state when dialog opens or worktree changes
|
// Reset state when dialog opens or worktree changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Reset all state on both open and close
|
||||||
|
resetState();
|
||||||
if (open) {
|
if (open) {
|
||||||
// Reset form fields
|
// Fetch fresh branches when dialog opens
|
||||||
setTitle('');
|
|
||||||
setBody('');
|
|
||||||
setCommitMessage('');
|
|
||||||
setBaseBranch(defaultBaseBranch);
|
|
||||||
setIsDraft(false);
|
|
||||||
setError(null);
|
|
||||||
// Also reset result states when opening for a new worktree
|
|
||||||
// This prevents showing stale PR URLs from previous worktrees
|
|
||||||
setPrUrl(null);
|
|
||||||
setBrowserUrl(null);
|
|
||||||
setShowBrowserFallback(false);
|
|
||||||
// Reset operation tracking
|
|
||||||
operationCompletedRef.current = false;
|
|
||||||
// Reset branches and fetch fresh ones
|
|
||||||
setBranches([]);
|
|
||||||
fetchBranches();
|
fetchBranches();
|
||||||
} else {
|
|
||||||
// Reset everything when dialog closes
|
|
||||||
setTitle('');
|
|
||||||
setBody('');
|
|
||||||
setCommitMessage('');
|
|
||||||
setBaseBranch(defaultBaseBranch);
|
|
||||||
setIsDraft(false);
|
|
||||||
setError(null);
|
|
||||||
setPrUrl(null);
|
|
||||||
setBrowserUrl(null);
|
|
||||||
setShowBrowserFallback(false);
|
|
||||||
operationCompletedRef.current = false;
|
|
||||||
setBranches([]);
|
|
||||||
}
|
}
|
||||||
}, [open, worktree?.path, defaultBaseBranch, fetchBranches]);
|
}, [open, worktree?.path, resetState, fetchBranches]);
|
||||||
|
|
||||||
const handleCreate = async () => {
|
const handleCreate = async () => {
|
||||||
if (!worktree) return;
|
if (!worktree) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user