git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Fix "inside work tree" detection on case-insensitive filesystems

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Sep 28, 2015, 16:12 UTC
Message-ID
<ac9733a6b922572ec10f09f89e07cde37ba43f13.1443456630.git.johannes.schindelin@gmx.de>

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>
---
 dir.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/dir.c b/dir.c
index b90484a..fba938b 100644
--- a/dir.c
+++ b/dir.c
@@ -2107,6 +2107,15 @@ int file_exists(const char *f)
 	return lstat(f, &sb) == 0;
 }
 
+static int cmp_icase(char a, char b)
+{
+	if (a == b)
+		return 0;
+	if (ignore_case)
+		return toupper(a) - toupper(b);
+	return a - b;
+}
+
 /*
  * Given two normalized paths (a trailing slash is ok), if subdir is
  * outside dir, return -1.  Otherwise return the offset in subdir that
@@ -2118,7 +2127,7 @@ int dir_inside_of(const char *subdir, const char *dir)
 
 	assert(dir && subdir && *dir && *subdir);
 
-	while (*dir && *subdir && *dir == *subdir) {
+	while (*dir && *subdir && !cmp_icase(*dir, *subdir)) {
 		dir++;
 		subdir++;
 		offset++;
-- 
2.5.3.windows.1.3.gc322723
Next: Michael Haggerty
Message 1 of 4 in “Fix "inside work tree" detection on case-insensitive filesystems”
  1. Fix "inside work tree" detection on case-insensitive filesystemsJohannes Schindelin, Sep 28, 2015
  2. Michael HaggertyDec 29, 2015
  3. Johannes SchindelinJan 1, 2016
  4. Michael HaggertyJan 1, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.