Merge branch 'en/merge-trivial-fix'

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
This commit is contained in:
Junio C Hamano 2016-04-25 15:17:15 -07:00
Родитель 9058b8f043 40d71940b6
Коммит f276cae187
2 изменённых файлов: 13 добавлений и 1 удалений

Просмотреть файл

@ -822,6 +822,14 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
{
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"));

Просмотреть файл

@ -27,7 +27,7 @@ test_expect_success 'setup' '
git tag c3
'
test_expect_success 'merge c1 to c2' '
merge_c1_to_c2_cmds='
git reset --hard c1 &&
git merge -s resolve c2 &&
test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
@ -41,6 +41,10 @@ test_expect_success 'merge c1 to c2' '
test 3 = $(git ls-files | wc -l)
'
test_expect_success 'merge c1 to c2' "$merge_c1_to_c2_cmds"
test_expect_success 'merge c1 to c2, again' "$merge_c1_to_c2_cmds"
test_expect_success 'merge c2 to c3 (fails)' '
git reset --hard c2 &&
test_must_fail git merge -s resolve c3