# Merge Execution and Verification

## Determine Merge Strategy

```bash
BRANCH_TYPE=$(echo $CURRENT | cut -d'/' -f1)

case "$BRANCH_TYPE" in
  feature)
    MERGE_STRATEGY="squash"
    DELETE_BRANCH=true
    ;;
  release|hotfix)
    MERGE_STRATEGY="merge"
    DELETE_BRANCH=true
    MERGE_BACK="$GF_DEVELOP_BRANCH"
    ;;
esac
```

## Execute Merge

**GitHub:**
```bash
case "$MERGE_STRATEGY" in
  squash)
    gh pr merge $PR_NUMBER --squash --delete-branch
    ;;
  merge)
    gh pr merge $PR_NUMBER --merge --delete-branch
    ;;
esac
```

**Azure DevOps:**
```bash
case "$MERGE_STRATEGY" in
  squash)
    az repos pr update --id $PR_NUMBER --status completed --squash true --delete-source-branch true
    ;;
  merge)
    az repos pr update --id $PR_NUMBER --status completed --squash false --delete-source-branch true
    ;;
esac
```

## Verify Merge

```bash
# CRITICAL: Force update tracking refs to get accurate state
git fetch origin $TARGET_BRANCH:refs/remotes/origin/$TARGET_BRANCH --force --quiet
git fetch origin --prune --quiet

MERGED=$(git branch -r --merged origin/$TARGET_BRANCH | grep "$CURRENT" | wc -l)

[ "$MERGED" -eq 0 ] && {
  echo "⚠️ Merge verification failed - branch may not be merged"
  echo "  → Check PR status on remote"
} || {
  echo "✅ Merge verified - branch merged to $TARGET_BRANCH"
}
```
