summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin-merge.c10
-rwxr-xr-xt/t7600-merge.sh9
2 files changed, 19 insertions, 0 deletions
diff --git a/builtin-merge.c b/builtin-merge.c
index 5c65a58699..afa01c659e 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -547,6 +547,16 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
int i = 0, ret;
struct commit_list *j;
struct strbuf buf;
+ int index_fd;
+ struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
+
+ index_fd = hold_locked_index(lock, 1);
+ refresh_cache(REFRESH_QUIET);
+ if (active_cache_changed &&
+ (write_cache(index_fd, active_cache, active_nr) ||
+ commit_locked_index(lock)))
+ return error("Unable to write index.");
+ rollback_lock_file(lock);
if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
int clean;
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 9516f541e9..7313ac278c 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -511,4 +511,13 @@ test_expect_success 'in-index merge' '
test_debug 'gitk --all'
+test_expect_success 'refresh the index before merging' '
+ git reset --hard c1 &&
+ sleep 1 &&
+ touch file &&
+ git merge c3
+'
+
+test_debug 'gitk --all'
+
test_done