Skip to content

Fix merge state not cleared when branch deletion fails during finish #97

@alexrinass

Description

@alexrinass

If deleteBranchesIfNeeded fails during finish (e.g., remote branch deletion fails), the merge state is never cleared. The user is then stuck in a "merge in progress" state even though the merge itself completed successfully.

Root Cause

In cmd/finish.go, ClearMergeState() (line 774) is called after deleteBranchesIfNeeded() (line 761). If delete returns an error, the function returns early and merge state cleanup is skipped:

if err := deleteBranchesIfNeeded(state, cfg.Remote, keepRemote, keepLocal, forceDelete); err != nil {
    return err  // <-- merge state never cleared
}

// ...

if err := mergestate.ClearMergeState(); err != nil {  // <-- never reached

Expected Behavior

Merge state should be cleared after a successful merge regardless of whether branch deletion succeeds. Branch deletion is a cleanup step — its failure should not leave the repository in an inconsistent state.

Suggested Fix

Either clear merge state before attempting branch deletion, or make branch deletion non-fatal (warn and continue). The latter aligns with the direction in #88 and PR #83.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions