Resolving Conflicts Inside Function Bodies
Handle merge conflicts that occur within function implementations where two branches modify logic, variables, or return values differently.
Detailed Explanation
Function Body Conflicts
When two branches modify the implementation of the same function, the resulting conflict requires careful analysis. Unlike simple value changes, function body conflicts involve logic flow, variable dependencies, and side effects that must all work together.
Typical Scenario
function calculateTotal(items) {
<<<<<<< HEAD
const subtotal = items.reduce((sum, item) => sum + item.price * item.qty, 0);
const tax = subtotal * 0.08;
const shipping = subtotal > 100 ? 0 : 9.99;
return { subtotal, tax, shipping, total: subtotal + tax + shipping };
=======
const subtotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
const discount = applyPromoCode(subtotal);
const tax = (subtotal - discount) * 0.08;
return { subtotal, discount, tax, total: subtotal - discount + tax };
>>>>>>> feature/promo-codes
Analysis Process
Before choosing a resolution, map out what each branch changed:
| Aspect | HEAD (ours) | Incoming (theirs) |
|---|---|---|
| Property name | item.qty |
item.quantity |
| Shipping logic | Added free shipping over $100 | Not present |
| Promo codes | Not present | Added discount calculation |
| Tax base | On full subtotal | On discounted subtotal |
Why Manual Edit Is Usually Required
Function body conflicts rarely lend themselves to Accept Ours, Accept Theirs, or Accept Both. Concatenating both versions would create duplicate variable declarations and two return statements. Instead, you need to understand both branches' intent and craft a unified implementation that includes both the shipping logic and the promo code discount.
Testing After Resolution
Always run the function's unit tests after resolving. If no tests exist, add them — a function that was modified by two branches simultaneously is clearly important enough to have test coverage.
Use Case
Two feature branches independently enhanced the same pricing function — one added free shipping logic and the other added promotional discount support. The merge creates a conflict in the function body.