Add post-merge hook, related documentation, and tests.
[gitweb.git] / unpack-trees.c
index d57b91c1b2738f205d7997cc67f25f594ff3e5ed..ccfeb6e245f32d88170ae51f0367ee15aa950a37 100644 (file)
@@ -667,7 +667,6 @@ int threeway_merge(struct cache_entry **stages,
        int no_anc_exists = 1;
        int i;
 
-       remove_entry(remove);
        for (i = 1; i < o->head_idx; i++) {
                if (!stages[i] || stages[i] == o->df_conflict_entry)
                        any_anc_missing = 1;
@@ -730,8 +729,10 @@ int threeway_merge(struct cache_entry **stages,
        }
 
        /* #1 */
-       if (!head && !remote && any_anc_missing)
+       if (!head && !remote && any_anc_missing) {
+               remove_entry(remove);
                return 0;
+       }
 
        /* Under the new "aggressive" rule, we resolve mostly trivial
         * cases that we historically had git-merge-one-file resolve.
@@ -763,6 +764,7 @@ int threeway_merge(struct cache_entry **stages,
                if ((head_deleted && remote_deleted) ||
                    (head_deleted && remote && remote_match) ||
                    (remote_deleted && head && head_match)) {
+                       remove_entry(remove);
                        if (index)
                                return deleted_entry(index, index, o);
                        else if (ce && !head_deleted)
@@ -785,6 +787,7 @@ int threeway_merge(struct cache_entry **stages,
                verify_uptodate(index, o);
        }
 
+       remove_entry(remove);
        o->nontrivial_merge = 1;
 
        /* #2, #3, #4, #6, #7, #9, #10, #11. */
@@ -827,7 +830,6 @@ int twoway_merge(struct cache_entry **src,
        struct cache_entry *oldtree = src[1];
        struct cache_entry *newtree = src[2];
 
-       remove_entry(remove);
        if (o->merge_size != 2)
                return error("Cannot do a twoway merge of %d trees",
                             o->merge_size);
@@ -850,6 +852,7 @@ int twoway_merge(struct cache_entry **src,
                }
                else if (oldtree && !newtree && same(current, oldtree)) {
                        /* 10 or 11 */
+                       remove_entry(remove);
                        return deleted_entry(oldtree, current, o);
                }
                else if (oldtree && newtree &&
@@ -859,6 +862,7 @@ int twoway_merge(struct cache_entry **src,
                }
                else {
                        /* all other failures */
+                       remove_entry(remove);
                        if (oldtree)
                                reject_merge(oldtree);
                        if (current)
@@ -870,8 +874,8 @@ int twoway_merge(struct cache_entry **src,
        }
        else if (newtree)
                return merged_entry(newtree, current, o);
-       else
-               return deleted_entry(oldtree, current, o);
+       remove_entry(remove);
+       return deleted_entry(oldtree, current, o);
 }
 
 /*