Skip to content

Commit 43e430d

Browse files
committed
Repo paths are now converted to real paths, as well as all paths involved in index related work.
That way, we don't try to compare a real-path to a non-real one, which would make the implementation think a file is not actually part of the repository. Fixes #224
1 parent dfb0a9c commit 43e430d

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

git/index/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ def _to_relative_path(self, path):
535535
if it is not within our git direcotory"""
536536
if not os.path.isabs(path):
537537
return path
538+
path = os.path.realpath(path)
538539
relative_path = path.replace(self.repo.working_tree_dir + os.sep, "")
539540
if relative_path == path:
540541
raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir))

git/repo/base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
128128
# walk up the path to find the .git dir
129129
while curpath:
130130
if is_git_dir(curpath):
131-
self.git_dir = curpath
132-
self._working_tree_dir = os.path.dirname(curpath)
131+
self.git_dir = os.path.realpath(curpath)
132+
self._working_tree_dir = os.path.dirname(self.git_dir)
133133
break
134134

135135
gitpath = find_git_dir(join(curpath, '.git'))
136136
if gitpath is not None:
137-
self.git_dir = gitpath
138-
self._working_tree_dir = curpath
137+
self.git_dir = os.path.realpath(gitpath)
138+
self._working_tree_dir = os.path.realpath(curpath)
139139
break
140140

141141
if not search_parent_directories:

git/test/lib/helper.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@ def wait(self):
6262

6363

6464
def _mktemp(*args):
65-
"""Wrapper around default tempfile.mktemp to fix an osx issue"""
65+
"""Wrapper around default tempfile.mktemp to fix an osx issue
66+
:note: the OSX special case was removed as it was unclear why that was needed in the first place. It seems
67+
to be just fine without it. However, if we leave this special case, and if TMPDIR is set to something custom,
68+
prefixing /private/ will lead to incorrect paths on OSX."""
6669
tdir = tempfile.mktemp(*args)
67-
if sys.platform == 'darwin':
68-
tdir = '/private' + tdir
70+
# See :note: above to learn why this is comented out.
71+
# if sys.platform == 'darwin':
72+
# tdir = '/private' + tdir
6973
return tdir
7074

7175

0 commit comments

Comments
 (0)