merge-recursive: enforce rule that index matches head before merging
[gitweb.git] / merge-recursive.c
index 171587bc7aab23bd7576ca7a5c2ad7d5ef42a942..352aa50fba1408037a0cb3d40639d5687492f027 100644 (file)
@@ -1974,6 +1974,13 @@ int merge_trees(struct merge_options *o,
                struct tree **result)
 {
        int code, clean;
+       struct strbuf sb = STRBUF_INIT;
+
+       if (!o->call_depth && index_has_changes(&the_index, head, &sb)) {
+               err(o, _("Your local changes to the following files would be overwritten by merge:\n  %s"),
+                   sb.buf);
+               return -1;
+       }
 
        if (o->subtree_shift) {
                merge = shift_tree_object(head, merge, o->subtree_shift);
@@ -1981,13 +1988,6 @@ int merge_trees(struct merge_options *o,
        }
 
        if (oid_eq(&common->object.oid, &merge->object.oid)) {
-               struct strbuf sb = STRBUF_INIT;
-
-               if (!o->call_depth && index_has_changes(&the_index, head, &sb)) {
-                       err(o, _("Your local changes to the following files would be overwritten by merge:\n  %s"),
-                           sb.buf);
-                       return -1;
-               }
                output(o, 0, _("Already up to date!"));
                *result = head;
                return 1;