Skip to content

Commit 6b46ec0

Browse files
committed
Merge branch 'nd/clone-case-smashing-warning' into pu
Running "git clone" against a project that contain two files with pathnames that differ only in cases on a case insensitive filesystem would result in one of the files lost because the underlying filesystem is incapable of holding both at the same time. An attempt is made to detect such a case and warn. Discussion getting petered out. Doing this portably and extending it to UTF-8 normalization issue HFS+ has would be costly. cf. <[email protected]> cf. <[email protected]> * nd/clone-case-smashing-warning: clone: report duplicate entries on case-insensitive filesystems
2 parents 5955621 + 7f851b2 commit 6b46ec0

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
@@ -712,6 +712,33 @@ static void update_head(const struct ref *our, const struct ref *remote,
712712
}
713713
}
714714

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

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

0 commit comments

Comments
 (0)