setup: fix "inside work tree" detection on case-insensitive filesystems

Git has a config variable to indicate that it is operating on a file system that is case-insensitive: core.ignoreCase. But the `dir_inside_of()` function did not respect that. As a result, if Git's idea of the current working directory disagreed in its upper/lower case with the `GIT_WORK_TREE` variable (e.g. `C:\test` vs `c:\test`) the user would be greeted by the error message fatal: git-am cannot be used without a working tree. when trying to run a rebase. This fixes https://github.com/git-for-windows/git/issues/402 (reported by Daniel Harding). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Sep 28, 2015 at 18:12 UTC 63ec5e1fecc14b0dd5452f0a2b80641600b03437
1 file changed +10 -1
dir.c
+10 -1
@@ -2030,6 +2030,15 @@ int file_exists(const char *f)
2030 return lstat(f, &sb) == 0;
2031 }
2032
2033 +static int cmp_icase(char a, char b)
2034 +{
2035 + if (a == b)
2036 + return 0;
2037 + if (ignore_case)
2038 + return toupper(a) - toupper(b);
2039 + return a - b;
2040 +}
2041 +
2042 /*
2043 * Given two normalized paths (a trailing slash is ok), if subdir is
2044 * outside dir, return -1. Otherwise return the offset in subdir that
@@ -2041,7 +2050,7 @@ int dir_inside_of(const char *subdir, const char *dir)
2050
2051 assert(dir && subdir && *dir && *subdir);
2052
2044 - while (*dir && *subdir && *dir == *subdir) {
2053 + while (*dir && *subdir && !cmp_icase(*dir, *subdir)) {
2054 dir++;
2055 subdir++;
2056 offset++;