Skip to content

Commit 76c3fb1

Browse files
committed
Merge branch 'mv/merge-refresh'
* mv/merge-refresh: builtin-merge: refresh the index before calling a strategy
2 parents c9618ff + 668f26f commit 76c3fb1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

builtin-merge.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,16 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
546546
int i = 0, ret;
547547
struct commit_list *j;
548548
struct strbuf buf;
549+
int index_fd;
550+
struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
551+
552+
index_fd = hold_locked_index(lock, 1);
553+
refresh_cache(REFRESH_QUIET);
554+
if (active_cache_changed &&
555+
(write_cache(index_fd, active_cache, active_nr) ||
556+
commit_locked_index(lock)))
557+
return error("Unable to write index.");
558+
rollback_lock_file(lock);
549559

550560
if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
551561
int clean;

t/t7600-merge.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,13 @@ test_expect_success 'in-index merge' '
511511

512512
test_debug 'gitk --all'
513513

514+
test_expect_success 'refresh the index before merging' '
515+
git reset --hard c1 &&
516+
sleep 1 &&
517+
touch file &&
518+
git merge c3
519+
'
520+
521+
test_debug 'gitk --all'
522+
514523
test_done

0 commit comments

Comments
 (0)