Skip to content

Commit a2f9f94

Browse files
committed
Merge branch 'issue-4203'
2 parents 2ad07ad + 32b8166 commit a2f9f94

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/merge.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3243,7 +3243,7 @@ int git_merge(
32433243
git_reference *our_ref = NULL;
32443244
git_checkout_options checkout_opts;
32453245
git_annotated_commit *our_head = NULL, *base = NULL;
3246-
git_index *index = NULL;
3246+
git_index *repo_index = NULL, *index = NULL;
32473247
git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
32483248
unsigned int checkout_strategy;
32493249
int error = 0;
@@ -3266,6 +3266,10 @@ int git_merge(
32663266
&checkout_strategy)) < 0)
32673267
goto done;
32683268

3269+
if ((error = git_repository_index(&repo_index, repo) < 0) ||
3270+
(error = git_index_read(repo_index, 0) < 0))
3271+
goto done;
3272+
32693273
/* Write the merge setup files to the repository. */
32703274
if ((error = git_annotated_commit_from_head(&our_head, repo)) < 0 ||
32713275
(error = git_merge__setup(repo, our_head, their_heads,
@@ -3299,6 +3303,7 @@ int git_merge(
32993303
git_annotated_commit_free(our_head);
33003304
git_annotated_commit_free(base);
33013305
git_reference_free(our_ref);
3306+
git_index_free(repo_index);
33023307

33033308
return error;
33043309
}

tests/merge/workdir/simple.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,35 @@ void test_merge_workdir_simple__automerge(void)
168168
git_index_free(index);
169169
}
170170

171+
void test_merge_workdir_simple__index_reload(void)
172+
{
173+
git_repository *tmp_repo;
174+
git_annotated_commit *their_heads[1];
175+
git_oid their_oid;
176+
git_index_entry entry = {{0}};
177+
git_index *tmp_index;
178+
179+
cl_git_pass(git_repository_open(&tmp_repo, git_repository_workdir(repo)));
180+
cl_git_pass(git_repository_index(&tmp_index, tmp_repo));
181+
cl_git_pass(git_index_read(repo_index, 0));
182+
183+
entry.mode = GIT_FILEMODE_BLOB;
184+
cl_git_pass(git_oid_fromstr(&entry.id, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2"));
185+
entry.path = "automergeable.txt";
186+
cl_git_pass(git_index_add(repo_index, &entry));
187+
188+
cl_git_pass(git_index_add_bypath(tmp_index, "automergeable.txt"));
189+
cl_git_pass(git_index_write(tmp_index));
190+
191+
cl_git_pass(git_oid_fromstr(&their_oid, THEIRS_SIMPLE_OID));
192+
cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oid));
193+
cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, NULL, NULL));
194+
195+
git_index_free(tmp_index);
196+
git_repository_free(tmp_repo);
197+
git_annotated_commit_free(their_heads[0]);
198+
}
199+
171200
void test_merge_workdir_simple__automerge_crlf(void)
172201
{
173202
#ifdef GIT_WIN32

0 commit comments

Comments
 (0)