Skip to content

Commit dc1ae70

Browse files
jjensengitster
authored andcommitted
Support case folding for git add when core.ignorecase=true
When MyDir/ABC/filea.txt is added to Git, the disk directory MyDir/ABC/ is renamed to mydir/aBc/, and then mydir/aBc/fileb.txt is added, the index will contain MyDir/ABC/filea.txt and mydir/aBc/fileb.txt. Although the earlier portions of this patch series account for those differences in case, this patch makes the pathing consistent by folding the case of newly added files against the first file added with that path. In read-cache.c's add_to_index(), the index_name_exists() support used for git status's case insensitive directory lookups is used to find the proper directory case according to what the user already checked in. That is, MyDir/ABC/'s case is used to alter the stored path for fileb.txt to MyDir/ABC/fileb.txt (instead of mydir/aBc/fileb.txt). This is especially important when cloning a repository to a case sensitive file system. MyDir/ABC/ and mydir/aBc/ exist in the same directory on a Windows machine, but on Linux, the files exist in two separate directories. The update to add_to_index(), in effect, treats a Windows file system as case sensitive by making path case consistent. Signed-off-by: Joshua Jensen <jjensen@workspacewhiz.com> Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 21444f1 commit dc1ae70

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

read-cache.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,29 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
608608
ce->ce_mode = ce_mode_from_stat(ent, st_mode);
609609
}
610610

611+
/* When core.ignorecase=true, determine if a directory of the same name but differing
612+
* case already exists within the Git repository. If it does, ensure the directory
613+
* case of the file being added to the repository matches (is folded into) the existing
614+
* entry's directory case.
615+
*/
616+
if (ignore_case) {
617+
const char *startPtr = ce->name;
618+
const char *ptr = startPtr;
619+
while (*ptr) {
620+
while (*ptr && *ptr != '/')
621+
++ptr;
622+
if (*ptr == '/') {
623+
struct cache_entry *foundce;
624+
++ptr;
625+
foundce = index_name_exists(&the_index, ce->name, ptr - ce->name, ignore_case);
626+
if (foundce) {
627+
memcpy((void *)startPtr, foundce->name + (startPtr - ce->name), ptr - startPtr);
628+
startPtr = ptr;
629+
}
630+
}
631+
}
632+
}
633+
611634
alias = index_name_exists(istate, ce->name, ce_namelen(ce), ignore_case);
612635
if (alias && !ce_stage(alias) && !ie_match_stat(istate, alias, st, ce_option)) {
613636
/* Nothing changed, really */

0 commit comments

Comments
 (0)