Skip to content

Commit 7f851b2

Browse files
pcloudsgitster
authored andcommitted
clone: report duplicate entries on case-insensitive filesystems
Paths that only differ in case work fine in a case-sensitive filesystems, but if those repos are cloned in a case-insensitive one, you'll get problems. The first thing to notice is "git status" will never be clean with no indication what's exactly is "dirty". This patch helps the situation a bit by pointing out the problem at clone time. I have not suggested any way to work around or fix this problem. But I guess we could probably have a section in Documentation/ dedicated to this problem and point there instead of a long advice in this warning. Another thing we probably should do is catch in "git checkout" too, not just "git clone" since your linux/unix colleage colleague may accidentally add some files that your mac/windows machine is not very happy with. But then there's another problem, once the problem is known, we probably should stop spamming this warning at every checkout, but how? Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ffc6fa0 commit 7f851b2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

builtin/clone.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,33 @@ static void update_head(const struct ref *our, const struct ref *remote,
711711
}
712712
}
713713

714+
static void find_duplicate_icase_entries(struct index_state *istate,
715+
struct string_list *dup)
716+
{
717+
struct string_list list = STRING_LIST_INIT_NODUP;
718+
int i;
719+
720+
for (i = 0; i < istate->cache_nr; i++)
721+
string_list_append(&list, istate->cache[i]->name);
722+
723+
list.cmp = fspathcmp;
724+
string_list_sort(&list);
725+
726+
for (i = 1; i < list.nr; i++) {
727+
const char *cur = list.items[i].string;
728+
const char *prev = list.items[i - 1].string;
729+
730+
if (dup->nr &&
731+
!fspathcmp(cur, dup->items[dup->nr - 1].string)) {
732+
string_list_append(dup, cur);
733+
} else if (!fspathcmp(cur, prev)) {
734+
string_list_append(dup, prev);
735+
string_list_append(dup, cur);
736+
}
737+
}
738+
string_list_clear(&list, 0);
739+
}
740+
714741
static int checkout(int submodule_progress)
715742
{
716743
struct object_id oid;
@@ -761,6 +788,20 @@ static int checkout(int submodule_progress)
761788
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
762789
die(_("unable to write new index file"));
763790

791+
if (ignore_case) {
792+
struct string_list dup = STRING_LIST_INIT_DUP;
793+
int i;
794+
795+
find_duplicate_icase_entries(&the_index, &dup);
796+
if (dup.nr) {
797+
warning(_("the following paths in this repository only differ in case and will\n"
798+
"cause problems because you have cloned it on an case-insensitive filesytem:\n"));
799+
for (i = 0; i < dup.nr; i++)
800+
fprintf(stderr, "\t%s\n", dup.items[i].string);
801+
}
802+
string_list_clear(&dup, 0);
803+
}
804+
764805
err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
765806
oid_to_hex(&oid), "1", NULL);
766807

0 commit comments

Comments
 (0)