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

Skip to content

Commit cc605e7

Browse files
committed
Merge pull request libgit2#3222 from git-up/conflicted
Fixed GIT_DELTA_CONFLICTED not returned in some cases
2 parents 09f3364 + 8d8a2ee commit cc605e7

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/diff.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,8 +1090,10 @@ static int handle_unmatched_new_item(
10901090
/* item contained in ignored directory, so skip over it */
10911091
return iterator_advance(&info->nitem, info->new_iter);
10921092

1093-
else if (info->new_iter->type != GIT_ITERATOR_TYPE_WORKDIR)
1094-
delta_type = GIT_DELTA_ADDED;
1093+
else if (info->new_iter->type != GIT_ITERATOR_TYPE_WORKDIR) {
1094+
if (delta_type != GIT_DELTA_CONFLICTED)
1095+
delta_type = GIT_DELTA_ADDED;
1096+
}
10951097

10961098
else if (nitem->mode == GIT_FILEMODE_COMMIT) {
10971099
/* ignore things that are not actual submodules */

tests/diff/index.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static void do_conflicted_diff(diff_expects *exp, unsigned long flags)
183183
cl_git_pass(git_repository_index(&index, g_repo));
184184

185185
ancestor.path = ours.path = theirs.path = "staged_changes";
186-
ancestor.mode = ours.mode = theirs.mode = 0100644;
186+
ancestor.mode = ours.mode = theirs.mode = GIT_FILEMODE_BLOB;
187187

188188
git_oid_fromstr(&ancestor.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
189189
git_oid_fromstr(&ours.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
@@ -239,3 +239,32 @@ void test_diff_index__reports_conflicts_when_reversed(void)
239239
cl_assert_equal_i(2, exp.line_adds);
240240
cl_assert_equal_i(5, exp.line_dels);
241241
}
242+
243+
void test_diff_index__not_in_head_conflicted(void)
244+
{
245+
const char *a_commit = "26a125ee1bf"; /* the current HEAD */
246+
git_index_entry theirs = {{0}};
247+
git_index *index;
248+
git_diff *diff;
249+
const git_diff_delta *delta;
250+
251+
git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
252+
253+
cl_git_pass(git_repository_index(&index, g_repo));
254+
cl_git_pass(git_index_read_tree(index, a));
255+
256+
theirs.path = "file_not_in_head";
257+
theirs.mode = GIT_FILEMODE_BLOB;
258+
git_oid_fromstr(&theirs.id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
259+
cl_git_pass(git_index_conflict_add(index, NULL, NULL, &theirs));
260+
261+
cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, index, NULL));
262+
263+
cl_assert_equal_i(git_diff_num_deltas(diff), 1);
264+
delta = git_diff_get_delta(diff, 0);
265+
cl_assert_equal_i(delta->status, GIT_DELTA_CONFLICTED);
266+
267+
git_diff_free(diff);
268+
git_index_free(index);
269+
git_tree_free(a);
270+
}

0 commit comments

Comments
 (0)