Skip to content

Commit

Permalink
setup: fix "inside work tree" detection on case-insensitive filesystems
Browse files Browse the repository at this point in the history
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 git-for-windows#402 (reported by
Daniel Harding).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
dscho authored and gitster committed Sep 28, 2015
1 parent ee6ad5f commit 63ec5e1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dir.c
Expand Up @@ -2030,6 +2030,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
Expand All @@ -2041,7 +2050,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++;
Expand Down

0 comments on commit 63ec5e1

Please sign in to comment.