Skip to content

ishaan812/Emdash/feat UI option merge to local#1295

Open
ishaan812 wants to merge 5 commits intogeneralaction:mainfrom
ishaan812:emdash/feat-ui-option-merge-6ez
Open

ishaan812/Emdash/feat UI option merge to local#1295
ishaan812 wants to merge 5 commits intogeneralaction:mainfrom
ishaan812:emdash/feat-ui-option-merge-6ez

Conversation

@ishaan812
Copy link

Add a "Local Merge" option to the PR action dropdown in the file changes
panel. This merges the worktree branch directly into the default branch
in the local repository.

A confirmation dialog warns the user about what will happen and allows
them to optionally customize the merge commit message.

Backend:

  • Add git:local-merge IPC handler that stages pending changes, resolves
    the main repo via git-common-dir, checks out the default branch, and
    merges the feature branch (with conflict recovery via merge --abort)
  • Extract shared helpers (detectDefaultBranch, getCurrentBranch,
    stageAndCommit) to deduplicate logic between merge-to-main and
    local-merge handlers

Frontend:

  • Add 'local-merge' to PrMode union with "Local Merge" label
  • Add confirmation dialog with yellow warning banner, step-by-step
    explanation, and optional commit message input
  • Extract shared executeMerge helper to deduplicate handleMergeToMain
    and handleLocalMerge

Closes #1269

@vercel
Copy link

vercel bot commented Mar 5, 2026

@ishaan812 is attempting to deploy a commit to the General Action Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 5, 2026

Greptile Summary

This PR introduces a "Local Merge" action to the PR action dropdown, allowing users to merge a worktree branch directly into the local default branch without creating a PR or pushing to remote. It also refactors shared git logic (branch detection, staging/committing) into reusable helpers used by both the existing merge-to-main and the new local-merge flow.

Key changes:

  • New git:local-merge IPC handler resolves the main repo via git rev-parse --git-common-dir, checks out the default branch, and merges the feature branch with conflict recovery via git merge --abort.
  • Shared helpers extracted: detectDefaultBranch (with gh CLI + git symbolic-ref fallbacks), getCurrentBranch, and stageAndCommit deduplicate logic across handlers.
  • Frontend adds 'local-merge' to the PrMode union, a confirmation dialog with a yellow warning banner and optional merge commit message input, and refactors handleMergeToMain into a shared executeMerge helper.

Two bugs in gitIpc.ts: (1) The git symbolic-ref fallback in detectDefaultBranch is unreachable when gh succeeds with empty output, silently falling back to 'main' for non-GitHub repos with a non-standard default branch. (2) stageAndCommit on the worktree runs before checking whether the main repo is in a clean state — if the subsequent git checkout in the main repo fails due to uncommitted changes there, the user's worktree changes are already permanently committed under an auto-generated message with no rollback path.

Minor style issue in FileChangesPanel.tsx: The isMergingToMain state name is now used for both merge-to-main and local-merge operations via the shared executeMerge helper, creating confusion for future maintainers who may interpret the name incorrectly.

Confidence Score: 2/5

  • Not safe to merge as-is — two logic bugs in the backend handler can leave the repo in an unexpected partial state or silently pick the wrong default branch.
  • The backend IPC handler has two bugs that affect correctness. The detectDefaultBranch fallback is structurally broken for the gh-available-but-empty-output case, causing silent fallback to 'main' for non-GitHub repos. Additionally, stageAndCommit fires before validating the main repo's working tree is clean, creating an irreversible partial-failure state if the subsequent checkout fails. Both bugs require fixes before this is safe to ship. The frontend changes are clean and well-structured, with only a minor naming clarity issue.
  • src/main/ipc/gitIpc.ts — specifically detectDefaultBranch (lines 528–548) and the operation ordering in the git:local-merge handler (lines 2157–2187).

Sequence Diagram

sequenceDiagram
    participant UI as FileChangesPanel
    participant IPC as git:local-merge (main)
    participant WT as Worktree (taskPath)
    participant MR as Main Repo (mainRepoPath)

    UI->>UI: User clicks "Local Merge"
    UI->>UI: Show confirmation dialog
    UI->>IPC: localMerge({ taskPath, commitMessage? })

    IPC->>WT: git branch --show-current
    WT-->>IPC: currentBranch
    IPC->>WT: gh / git symbolic-ref (detectDefaultBranch)
    WT-->>IPC: defaultBranch

    IPC->>WT: git status --porcelain (stageAndCommit)
    WT-->>IPC: dirty?
    IPC->>WT: git add -A + git commit (if dirty)

    IPC->>WT: git rev-parse --git-common-dir
    WT-->>IPC: commonDir → mainRepoPath

    IPC->>MR: git checkout defaultBranch
    MR-->>IPC: ok / error

    alt checkout succeeds
        IPC->>MR: git merge currentBranch -m commitMessage
        MR-->>IPC: merged / conflicts
        alt conflicts
            IPC->>MR: git merge --abort
        end
    end

    IPC-->>UI: { success, output, defaultBranch, featureBranch } / { error }
    UI->>UI: toast + refreshChanges()
Loading

Last reviewed commit: 5e84bf6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add UI option for local merge without PR

1 participant