Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c0b10c2

Browse files
author
Edward Thomson
committed
Merge wd validation tests against index not HEAD
Validating the workdir should not compare HEAD to working directory - this is both inefficient (as it ignores the cache) and incorrect. If we had legitimately allowed changes in the index (identical to the merge result) then comparing HEAD to workdir would reject these changes as different. Further, this will identify files that were filtered strangely as modified, while testing with the cache would prevent this. Also, it's stupid slow.
1 parent bb13d39 commit c0b10c2

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/merge.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,7 @@ static int merge_check_index(size_t *conflicts, git_repository *repo, git_index
23302330

23312331
static int merge_check_workdir(size_t *conflicts, git_repository *repo, git_index *index_new, git_vector *merged_paths)
23322332
{
2333-
git_tree *head_tree = NULL;
2333+
git_index *index_repo = NULL;
23342334
git_diff *wd_diff_list = NULL;
23352335
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
23362336
int error = 0;
@@ -2341,23 +2341,20 @@ static int merge_check_workdir(size_t *conflicts, git_repository *repo, git_inde
23412341

23422342
opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED;
23432343

2344-
if ((error = git_repository_head_tree(&head_tree, repo)) < 0)
2345-
goto done;
2346-
23472344
/* Workdir changes may exist iff they do not conflict with changes that
23482345
* will be applied by the merge (including conflicts). Ensure that there
23492346
* are no changes in the workdir to these paths.
23502347
*/
23512348
opts.pathspec.count = merged_paths->length;
23522349
opts.pathspec.strings = (char **)merged_paths->contents;
23532350

2354-
if ((error = git_diff_tree_to_workdir(&wd_diff_list, repo, head_tree, &opts)) < 0)
2351+
if ((error = git_diff_index_to_workdir(&wd_diff_list, repo, index_repo, &opts)) < 0)
23552352
goto done;
23562353

23572354
*conflicts = wd_diff_list->deltas.length;
23582355

23592356
done:
2360-
git_tree_free(head_tree);
2357+
git_index_free(index_repo);
23612358
git_diff_free(wd_diff_list);
23622359

23632360
return error;

0 commit comments

Comments
 (0)