Skip to content

Commit 4c154c3

Browse files
committed
Use the real path of the cache root
1 parent 450d617 commit 4c154c3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pre_commit/store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ def _get_default_directory() -> str:
3030
`Store.get_default_directory` can be mocked in tests and
3131
`_get_default_directory` can be tested.
3232
"""
33-
return os.environ.get('PRE_COMMIT_HOME') or os.path.join(
33+
ret = os.environ.get('PRE_COMMIT_HOME') or os.path.join(
3434
os.environ.get('XDG_CACHE_HOME') or os.path.expanduser('~/.cache'),
3535
'pre-commit',
3636
)
37+
return os.path.realpath(ret)
3738

3839

3940
class Store:

tests/store_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,26 @@ def test_our_session_fixture_works():
2525
def test_get_default_directory_defaults_to_home():
2626
# Not we use the module level one which is not mocked
2727
ret = _get_default_directory()
28-
assert ret == os.path.join(os.path.expanduser('~/.cache'), 'pre-commit')
28+
expected = os.path.realpath(os.path.expanduser('~/.cache/pre-commit'))
29+
assert ret == expected
2930

3031

3132
def test_adheres_to_xdg_specification():
3233
with mock.patch.dict(
3334
os.environ, {'XDG_CACHE_HOME': '/tmp/fakehome'},
3435
):
3536
ret = _get_default_directory()
36-
assert ret == os.path.join('/tmp/fakehome', 'pre-commit')
37+
expected = os.path.realpath('/tmp/fakehome/pre-commit')
38+
assert ret == expected
3739

3840

3941
def test_uses_environment_variable_when_present():
4042
with mock.patch.dict(
4143
os.environ, {'PRE_COMMIT_HOME': '/tmp/pre_commit_home'},
4244
):
4345
ret = _get_default_directory()
44-
assert ret == '/tmp/pre_commit_home'
46+
expected = os.path.realpath('/tmp/pre_commit_home')
47+
assert ret == expected
4548

4649

4750
def test_store_init(store):

0 commit comments

Comments
 (0)