Skip to content

Commit f276cae

Browse files
committed
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
2 parents 9058b8f + 40d7194 commit f276cae

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

builtin/merge.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,14 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
822822
{
823823
unsigned char result_tree[20], result_commit[20];
824824
struct commit_list *parents, **pptr = &parents;
825+
static struct lock_file lock;
826+
827+
hold_locked_index(&lock, 1);
828+
refresh_cache(REFRESH_QUIET);
829+
if (active_cache_changed &&
830+
write_locked_index(&the_index, &lock, COMMIT_LOCK))
831+
return error(_("Unable to write index."));
832+
rollback_lock_file(&lock);
825833

826834
write_tree_trivial(result_tree);
827835
printf(_("Wonderful.\n"));

t/t7605-merge-resolve.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test_expect_success 'setup' '
2727
git tag c3
2828
'
2929

30-
test_expect_success 'merge c1 to c2' '
30+
merge_c1_to_c2_cmds='
3131
git reset --hard c1 &&
3232
git merge -s resolve c2 &&
3333
test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
@@ -41,6 +41,10 @@ test_expect_success 'merge c1 to c2' '
4141
test 3 = $(git ls-files | wc -l)
4242
'
4343

44+
test_expect_success 'merge c1 to c2' "$merge_c1_to_c2_cmds"
45+
46+
test_expect_success 'merge c1 to c2, again' "$merge_c1_to_c2_cmds"
47+
4448
test_expect_success 'merge c2 to c3 (fails)' '
4549
git reset --hard c2 &&
4650
test_must_fail git merge -s resolve c3

0 commit comments

Comments
 (0)