8000 Merge pull request #6729 from libgit2/ethomson/index_add · libgit2/libgit2@cbff31d · GitHub
[go: up one dir, main page]

Skip to content

Commit cbff31d

Browse files
authored
Merge pull request #6729 from libgit2/ethomson/index_add
Correct index add directory/file conflict detection
2 parents 802f08c + 18ea0b0 commit cbff31d

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/libgit2/index.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,10 +1185,13 @@ static int has_dir_name(git_index *index,
11851185
size_t len, pos;
11861186

11871187
for (;;) {
1188-
if (*--slash == '/')
1189-
break;
1188+
slash--;
1189+
11901190
if (slash <= entry->path)
11911191
return 0;
1192+
1193+
if (*slash == '/')
1194+
break;
11921195
}
11931196
len = slash - name;
11941197

tests/libgit2/index/add.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,27 @@ void test_index_add__invalid_entries_succeeds_by_default(void)
8282
test_add_entry(true, valid_commit_id, GIT_FILEMODE_LINK);
8383
}
8484

85+
void test_index_add__two_slash_prefixed(void)
86+
{
87+
git_index_entry one = {{0}}, two = {{0}};
88+
const git_index_entry *result;
89+
size_t orig_count;
90+
91+
orig_count = git_index_entrycount(g_index);
92+
93+
cl_git_pass(git_oid__fromstr(&one.id, "fa49b077972391ad58037050f2a75f74e3671e92", GIT_OID_SHA1));
94+
one.path = "/a";
95+
one.mode = GIT_FILEMODE_BLOB;
96+
97+
cl_git_pass(git_oid__fromstr(&two.id, "3697d64be941a53d4ae8f6a271e4e3fa56b022cc", GIT_OID_SHA1));
98+
two.path = "/a";
99+
two.mode = GIT_FILEMODE_BLOB;
100+
101+
cl_git_pass(git_index_add(g_index, &one));
102+
cl_git_pass(git_index_add(g_index, &two));
103+
104+
cl_assert_equal_i(orig_count + 1, git_index_entrycount(g_index));
105+
106+
cl_assert(result = git_index_get_bypath(g_index, "/a", 0));
107+
cl_assert_equal_oid(&two.id, &result->id);
108+
}

0 commit comments

Comments
 (0)
0