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

Skip to content

Commit 3f5877d

Browse files
committed
Merge pull request libgit2#2534 from libgit2/ntk/case_index_conflicts
Failing test for case sensitive conflicts in the index
2 parents 1c34b71 + ad8509e commit 3f5877d

File tree

3 files changed

+98
-6
lines changed

3 files changed

+98
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ v0.23 + 1
4141
with which to implement the transactional/atomic semantics for the
4242
configuration backend.
4343

44-
* `git_index_add` will now use the case as provided by the caller on
45-
case insensitive systems. Previous versions would keep the case as
46-
it existed in the index. This does not affect the higher-level
47-
`git_index_add_bypath` or `git_index_add_frombuffer` functions.
44+
* `git_index_add` and `git_index_conflict_add()` will now use the case
45+
as provided by the caller on case insensitive systems. Previous
46+
versions would keep the case as it existed in the index. This does
47+
not affect the higher-level `git_index_add_bypath` or
48+
`git_index_add_frombuffer` functions.
4849

4950
* The `notify_payload` field of `git_diff_options` was renamed to `payload`
5051
to reflect that it's also the payload for the new progress callback.

src/index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ int git_index_conflict_add(git_index *index,
16911691
for (i = 0; i < 3; i++) {
16921692
if (entries[i] && !valid_filemode(entries[i]->mode)) {
16931693
giterr_set(GITERR_INDEX, "invalid filemode for stage %d entry",
1694-
i);
1694+
i + 1);
16951695
return -1;
16961696
}
16971697
}
@@ -1718,7 +1718,7 @@ int git_index_conflict_add(git_index *index,
17181718
/* Make sure stage is correct */
17191719
GIT_IDXENTRY_STAGE_SET(entries[i], i + 1);
17201720

1721-
if ((ret = index_insert(index, &entries[i], 0, true, true)) < 0)
1721+
if ((ret = index_insert(index, &entries[i], 1, true, true)) < 0)
17221722
goto on_error;
17231723

17241724
entries[i] = NULL; /* don't free if later entry fails */

tests/index/conflicts.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,94 @@ void test_index_conflicts__partial(void)
342342
cl_assert(conflict_entry[1] == NULL);
343343
cl_assert(conflict_entry[2] == NULL);
344344
}
345+
346+
void test_index_conflicts__case_matters(void)
347+
{
348+
const git_index_entry *conflict_entry[3];
349+
git_oid oid;
350+
const char *upper_case = "DIFFERS-IN-CASE.TXT";
351+
const char *mixed_case = "Differs-In-Case.txt";
352+
const char *correct_case;
353+
bool ignorecase = cl_repo_get_bool(repo, "core.ignorecase");
354+
355+
git_index_entry ancestor_entry, our_entry, their_entry;
356+
357+
memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
358+
memset(&our_entry, 0x0, sizeof(git_index_entry));
359+
memset(&their_entry, 0x0, sizeof(git_index_entry));
360+
361+
ancestor_entry.path = upper_case;
362+
GIT_IDXENTRY_STAGE_SET(&ancestor_entry, GIT_INDEX_STAGE_ANCESTOR);
363+
git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID);
364+
ancestor_entry.mode = GIT_FILEMODE_BLOB;
365+
366+
our_entry.path = upper_case;
367+
GIT_IDXENTRY_STAGE_SET(&our_entry, GIT_INDEX_STAGE_OURS);
368+
git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID);
369+
our_entry.mode = GIT_FILEMODE_BLOB;
370+
371+
their_entry.path = upper_case;
372+
GIT_IDXENTRY_STAGE_SET(&their_entry, GIT_INDEX_STAGE_THEIRS);
373+
git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID);
374+
their_entry.mode = GIT_FILEMODE_BLOB;
375+
376+
cl_git_pass(git_index_conflict_add(repo_index,
377+
&ancestor_entry, &our_entry, &their_entry));
378+
379+
ancestor_entry.path = mixed_case;
380+
GIT_IDXENTRY_STAGE_SET(&ancestor_entry, GIT_INDEX_STAGE_ANCESTOR);
381+
git_oid_fromstr(&ancestor_entry.id, CONFLICTS_TWO_ANCESTOR_OID);
382+
ancestor_entry.mode = GIT_FILEMODE_BLOB;
383+
384+
our_entry.path = mixed_case;
385+
GIT_IDXENTRY_STAGE_SET(&ancestor_entry, GIT_INDEX_STAGE_ANCESTOR);
386+
git_oid_fromstr(&our_entry.id, CONFLICTS_TWO_OUR_OID);
387+
ancestor_entry.mode = GIT_FILEMODE_BLOB;
388+
389+
their_entry.path = mixed_case;
390+
GIT_IDXENTRY_STAGE_SET(&their_entry, GIT_INDEX_STAGE_THEIRS);
391+
git_oid_fromstr(&their_entry.id, CONFLICTS_TWO_THEIR_OID);
392+
their_entry.mode = GIT_FILEMODE_BLOB;
393+
394+
cl_git_pass(git_index_conflict_add(repo_index,
395+
&ancestor_entry, &our_entry, &their_entry));
396+
397+
cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
398+
&conflict_entry[2], repo_index, upper_case));
399+
400+
/*
401+
* We inserted with mixed case last, so on a case-insensitive
402+
* fs we should get the mixed case.
403+
*/
404+
if (ignorecase)
405+
correct_case = mixed_case;
406+
else
407+
correct_case = upper_case;
408+
409+
cl_assert_equal_s(correct_case, conflict_entry[0]->path);
410+
git_oid_fromstr(&oid, ignorecase ? CONFLICTS_TWO_ANCESTOR_OID : CONFLICTS_ONE_ANCESTOR_OID);
411+
cl_assert_equal_oid(&oid, &conflict_entry[0]->id);
412+
413+
cl_assert_equal_s(correct_case, conflict_entry[1]->path);
414+
git_oid_fromstr(&oid, ignorecase ? CONFLICTS_TWO_OUR_OID : CONFLICTS_ONE_OUR_OID);
415+
cl_assert_equal_oid(&oid, &conflict_entry[1]->id);
416+
417+
cl_assert_equal_s(correct_case, conflict_entry[2]->path);
418+
git_oid_fromstr(&oid, ignorecase ? CONFLICTS_TWO_THEIR_OID : CONFLICTS_ONE_THEIR_OID);
419+
cl_assert_equal_oid(&oid, &conflict_entry[2]->id);
420+
421+
cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1],
422+
&conflict_entry[2], repo_index, mixed_case));
423+
424+
cl_assert_equal_s(mixed_case, conflict_entry[0]->path);
425+
git_oid_fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID);
426+
cl_assert_equal_oid(&oid, &conflict_entry[0]->id);
427+
428+
cl_assert_equal_s(mixed_case, conflict_entry[1]->path);
429+
git_oid_fromstr(&oid, CONFLICTS_TWO_OUR_OID);
430+
cl_assert_equal_oid(&oid, &conflict_entry[1]->id);
431+
432+
cl_assert_equal_s(mixed_case, conflict_entry[2]->path);
433+
git_oid_fromstr(&oid, CONFLICTS_TWO_THEIR_OID);
434+
cl_assert_equal_oid(&oid, &conflict_entry[2]->id);
435+
}

0 commit comments

Comments
 (0)