mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
Merge branch 'kthrift-fix/prevent-cwd-tilde-dir-creation'
This commit is contained in:
commit
cae76eb55f
@ -1,5 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
import six
|
import six
|
||||||
|
import os
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
from thefuck import const
|
from thefuck import const
|
||||||
|
|
||||||
@ -101,3 +102,22 @@ class TestInitializeSettingsFile(object):
|
|||||||
for setting in const.DEFAULT_SETTINGS.items():
|
for setting in const.DEFAULT_SETTINGS.items():
|
||||||
assert '# {} = {}\n'.format(*setting) in settings_file_contents
|
assert '# {} = {}\n'.format(*setting) in settings_file_contents
|
||||||
settings_file.close()
|
settings_file.close()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('legacy_dir_exists, xdg_config_home, result', [
|
||||||
|
(False, '~/.config', '~/.config/thefuck'),
|
||||||
|
(False, '/user/test/config/', '/user/test/config/thefuck'),
|
||||||
|
(True, '~/.config', '~/.thefuck'),
|
||||||
|
(True, '/user/test/config/', '~/.thefuck')])
|
||||||
|
def test_get_user_dir_path(mocker, environ, settings, legacy_dir_exists,
|
||||||
|
xdg_config_home, result):
|
||||||
|
mocker.patch('thefuck.conf.Path.is_dir',
|
||||||
|
return_value=legacy_dir_exists)
|
||||||
|
|
||||||
|
if xdg_config_home is not None:
|
||||||
|
environ['XDG_CONFIG_HOME'] = xdg_config_home
|
||||||
|
else:
|
||||||
|
environ.pop('XDG_CONFIG_HOME', None)
|
||||||
|
|
||||||
|
path = settings._get_user_dir_path().as_posix()
|
||||||
|
assert path == os.path.expanduser(result)
|
||||||
|
@ -40,16 +40,18 @@ class Settings(dict):
|
|||||||
settings_file.write(u'# {} = {}\n'.format(*setting))
|
settings_file.write(u'# {} = {}\n'.format(*setting))
|
||||||
|
|
||||||
def _get_user_dir_path(self):
|
def _get_user_dir_path(self):
|
||||||
# for backward compatibility, use `~/.thefuck` if it exists
|
"""Returns Path object representing the user config resource"""
|
||||||
legacy_user_dir = Path('~/.thefuck').expanduser()
|
xdg_config_home = os.environ.get('XDG_CONFIG_HOME', '~/.config')
|
||||||
|
user_dir = Path(xdg_config_home, 'thefuck').expanduser()
|
||||||
|
legacy_user_dir = Path('~', '.thefuck').expanduser()
|
||||||
|
|
||||||
|
# For backward compatibility use legacy '~/.thefuck' if it exists:
|
||||||
if legacy_user_dir.is_dir():
|
if legacy_user_dir.is_dir():
|
||||||
warn('~/.thefuck is deprecated, please move '
|
warn(u'Config path {} is deprecated. Please move to {}'.format(
|
||||||
'config to ~/.config/thefuck')
|
legacy_user_dir, user_dir))
|
||||||
return legacy_user_dir
|
return legacy_user_dir
|
||||||
else:
|
else:
|
||||||
xdg_config_dir = os.getenv("XDG_CONFIG_HOME", "~/.config")
|
return user_dir
|
||||||
return Path(xdg_config_dir).joinpath('thefuck')
|
|
||||||
|
|
||||||
def _setup_user_dir(self):
|
def _setup_user_dir(self):
|
||||||
"""Returns user config dir, create it when it doesn't exist."""
|
"""Returns user config dir, create it when it doesn't exist."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user