a73x

903cf337

Update working tree after patch merge when on target branch

a73x   2026-03-22 07:48

After merge updates the base ref, check if HEAD points to the same
branch and checkout to sync the working tree and index.

Fixes: 478e4576

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

diff --git a/src/patch.rs b/src/patch.rs
index 20e23de..7a50c12 100644
--- a/src/patch.rs
+++ b/src/patch.rs
@@ -448,6 +448,17 @@ pub fn merge(repo: &Repository, id_prefix: &str) -> Result<PatchState, crate::er
        )?;
    }

    // Update working tree if HEAD is on the target branch
    if let Ok(head_ref) = repo.head() {
        if head_ref.is_branch()
            && head_ref.shorthand() == Some(&p.base_ref)
        {
            repo.checkout_head(Some(
                git2::build::CheckoutBuilder::new().force(),
            ))?;
        }
    }

    // Record the merge event in the patch DAG
    let author = get_author(repo)?;
    let event = Event {