Skip to content

Commit e8d373c

Browse files
committed
merge: add error handling for index reload
Cleans up should git_repository_index or git_index_read fail
1 parent 5248a1a commit e8d373c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/merge.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,9 +3239,6 @@ int git_merge(
32393239

32403240
assert(repo && their_heads);
32413241

3242-
git_repository_index(&index, repo);
3243-
git_index_read(index, 0);
3244-
32453242
if (their_heads_len != 1) {
32463243
giterr_set(GITERR_MERGE, "can only merge a single branch");
32473244
return -1;
@@ -3258,6 +3255,10 @@ int git_merge(
32583255
&checkout_strategy)) < 0)
32593256
goto done;
32603257

3258+
if ((error = git_repository_index(&index, repo) < 0) ||
3259+
(error = git_index_read(index, 0) < 0))
3260+
goto done;
3261+
32613262
/* Write the merge setup files to the repository. */
32623263
if ((error = git_annotated_commit_from_head(&our_head, repo)) < 0 ||
32633264
(error = git_merge__setup(repo, our_head, their_heads,

0 commit comments

Comments
 (0)