Merge branch 'en/merge-trivial-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 25 Apr 2016 22:17:15 +0000 (15:17 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Apr 2016 22:17:15 +0000 (15:17 -0700)
When "git merge" notices that the merge can be resolved purely at
the tree level (without having to merge blobs) and the resulting
tree happens to already exist in the object store, it forgot to
update the index, which lead to an inconsistent state for later
operations.

* en/merge-trivial-fix:
builtin/merge.c: fix a bug with trivial merges
t7605: add a testcase demonstrating a bug with trivial merges

1  2 
builtin/merge.c
diff --combined builtin/merge.c
index 1ec44f0c1b241ed7c05efefc427a7923241c1db1,eb9415119f0b3d4738d235b593f5aff0ab51be49..b555a1bf9cd46ea57bcbe1c8d8b7ac146fe9f81c
@@@ -822,6 -822,14 +822,14 @@@ static int merge_trivial(struct commit 
  {
        unsigned char result_tree[20], result_commit[20];
        struct commit_list *parents, **pptr = &parents;
+       static struct lock_file lock;
+       hold_locked_index(&lock, 1);
+       refresh_cache(REFRESH_QUIET);
+       if (active_cache_changed &&
+           write_locked_index(&the_index, &lock, COMMIT_LOCK))
+               return error(_("Unable to write index."));
+       rollback_lock_file(&lock);
  
        write_tree_trivial(result_tree);
        printf(_("Wonderful.\n"));
@@@ -1168,7 -1176,7 +1176,7 @@@ int cmd_merge(int argc, const char **ar
        struct commit *head_commit;
        struct strbuf buf = STRBUF_INIT;
        const char *head_arg;
 -      int flag, i, ret = 0, head_subsumed;
 +      int i, ret = 0, head_subsumed;
        int best_cnt = -1, merge_was_ok = 0, automerge_was_ok = 0;
        struct commit_list *common = NULL;
        const char *best_strategy = NULL, *wt_strategy = NULL;
         * Check if we are _not_ on a detached HEAD, i.e. if there is a
         * current branch.
         */
 -      branch = branch_to_free = resolve_refdup("HEAD", 0, head_sha1, &flag);
 +      branch = branch_to_free = resolve_refdup("HEAD", 0, head_sha1, NULL);
        if (branch && starts_with(branch, "refs/heads/"))
                branch += 11;
        if (!branch || is_null_sha1(head_sha1))