Skip to content

Commit 18d3542

Browse files
committed
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 from 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 #402 (reported by Daniel Harding). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent ec5e5c6 commit 18d3542

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

dir.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,15 @@ int file_exists(const char *f)
20302030
return lstat(f, &sb) == 0;
20312031
}
20322032

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+
20332042
/*
20342043
* Given two normalized paths (a trailing slash is ok), if subdir is
20352044
* 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)
20412050

20422051
assert(dir && subdir && *dir && *subdir);
20432052

2044-
while (*dir && *subdir && *dir == *subdir) {
2053+
while (*dir && *subdir && !cmp_icase(*dir, *subdir)) {
20452054
dir++;
20462055
subdir++;
20472056
offset++;

0 commit comments

Comments
 (0)