Skip to content

Commit 0a56fd3

Browse files
committed
Normalize case when looking up file in git file list
1 parent f0fe1a0 commit 0a56fd3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

setuptools_scm/git_file_finder.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def _git_toplevel(path):
88
out = subprocess.check_output([
99
'git', 'rev-parse', '--show-toplevel',
1010
], cwd=(path or '.'), universal_newlines=True)
11-
return os.path.realpath(out.strip())
11+
return os.path.normcase(os.path.realpath(out.strip()))
1212
except subprocess.CalledProcessError:
1313
# git returned error, we are not in a git repo
1414
return None
@@ -26,7 +26,7 @@ def _git_ls_files_and_dirs(toplevel):
2626
git_files = set()
2727
git_dirs = set([toplevel])
2828
for member in tf.getmembers():
29-
name = member.name.replace('/', os.path.sep)
29+
name = os.path.normcase(member.name).replace('/', os.path.sep)
3030
if member.type == tarfile.DIRTYPE:
3131
git_dirs.add(name)
3232
else:
@@ -44,19 +44,21 @@ def find_files(path=''):
4444
if not toplevel:
4545
return []
4646
git_files, git_dirs = _git_ls_files_and_dirs(toplevel)
47-
realpath = os.path.realpath(path)
47+
realpath = os.path.normcase(os.path.realpath(path))
4848
assert realpath.startswith(toplevel)
4949
assert realpath in git_dirs
5050
seen = set()
5151
res = []
5252
for dirpath, dirnames, filenames in os.walk(realpath, followlinks=True):
53-
realdirpath = os.path.realpath(dirpath) # resolve symlink
53+
# dirpath with symlinks resolved
54+
realdirpath = os.path.normcase(os.path.realpath(dirpath))
5455
if realdirpath not in git_dirs or realdirpath in seen:
5556
dirnames[:] = []
5657
continue
5758
for filename in filenames:
58-
fullfilename = os.path.join(dirpath, filename) # with symlink
59-
if os.path.realpath(fullfilename) in git_files:
59+
# dirpath + filename with symlinks preserved
60+
fullfilename = os.path.join(dirpath, filename)
61+
if os.path.normcase(os.path.realpath(fullfilename)) in git_files:
6062
res.append(
6163
os.path.join(path, os.path.relpath(fullfilename, path)))
6264
seen.add(realdirpath)

0 commit comments

Comments
 (0)