Skip to content

Commit fd7ab1d

Browse files
authored
Merge pull request libgit2#4776 from pks-t/pks/test-index-invalid-filemode
tests: verify adding index conflicts with invalid filemodes fails
2 parents 503af77 + 3a1f5df commit fd7ab1d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/index/conflicts.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,48 @@ void test_index_conflicts__add_fixes_incorrect_stage(void)
9191
cl_assert(git_index_entry_stage(conflict_entry[2]) == 3);
9292
}
9393

94+
void test_index_conflicts__add_detects_invalid_filemode(void)
95+
{
96+
git_index_entry ancestor_entry, our_entry, their_entry;
97+
git_index_entry *conflict_entry[3];
98+
int i;
99+
100+
cl_assert(git_index_entrycount(repo_index) == 8);
101+
102+
memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
103+
memset(&our_entry, 0x0, sizeof(git_index_entry));
104+
memset(&their_entry, 0x0, sizeof(git_index_entry));
105+
106+
conflict_entry[0] = &ancestor_entry;
107+
conflict_entry[1] = &our_entry;
108+
conflict_entry[2] = &their_entry;
109+
110+
for (i = 0; i < 3; i++) {
111+
ancestor_entry.path = "test-one.txt";
112+
ancestor_entry.mode = 0100644;
113+
GIT_IDXENTRY_STAGE_SET(&ancestor_entry, 3);
114+
git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID);
115+
116+
our_entry.path = "test-one.txt";
117+
our_entry.mode = 0100644;
118+
GIT_IDXENTRY_STAGE_SET(&our_entry, 1);
119+
git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID);
120+
121+
their_entry.path = "test-one.txt";
122+
their_entry.mode = 0100644;
123+
GIT_IDXENTRY_STAGE_SET(&their_entry, 2);
124+
git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID);
125+
126+
/* Corrupt the conflict entry's mode */
127+
conflict_entry[i]->mode = 027431745;
128+
129+
cl_git_fail(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry));
130+
}
131+
132+
cl_assert(git_index_entrycount(repo_index) == 8);
133+
}
134+
135+
94136
void test_index_conflicts__add_removes_stage_zero(void)
95137
{
96138
git_index_entry ancestor_entry, our_entry, their_entry;

0 commit comments

Comments
 (0)