mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 01:51:46 +04:00
Use expanduser in init-templatedir like git does
This commit is contained in:
parent
cab8036db3
commit
f48c0abcbe
2 changed files with 19 additions and 1 deletions
|
|
@ -18,7 +18,7 @@ def init_templatedir(config_file, store, directory, hook_type):
|
||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
configured_path = None
|
configured_path = None
|
||||||
else:
|
else:
|
||||||
configured_path = os.path.realpath(out.strip())
|
configured_path = os.path.realpath(os.path.expanduser(out.strip()))
|
||||||
dest = os.path.realpath(directory)
|
dest = os.path.realpath(directory)
|
||||||
if configured_path != dest:
|
if configured_path != dest:
|
||||||
logger.warning('`init.templateDir` not set to the target directory')
|
logger.warning('`init.templateDir` not set to the target directory')
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
import pre_commit.constants as C
|
import pre_commit.constants as C
|
||||||
from pre_commit.commands.init_templatedir import init_templatedir
|
from pre_commit.commands.init_templatedir import init_templatedir
|
||||||
from pre_commit.envcontext import envcontext
|
from pre_commit.envcontext import envcontext
|
||||||
|
|
@ -61,3 +64,18 @@ def test_init_templatedir_not_set(tmpdir, store, cap_out):
|
||||||
assert lines[1] == (
|
assert lines[1] == (
|
||||||
'[WARNING] `init.templateDir` not set to the target directory'
|
'[WARNING] `init.templateDir` not set to the target directory'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_init_templatedir_expanduser(tmpdir, tempdir_factory, store, cap_out):
|
||||||
|
target = str(tmpdir.join('tmpl'))
|
||||||
|
tmp_git_dir = git_dir(tempdir_factory)
|
||||||
|
with cwd(tmp_git_dir):
|
||||||
|
cmd_output('git', 'config', 'init.templateDir', '~/templatedir')
|
||||||
|
with mock.patch.object(os.path, 'expanduser', return_value=target):
|
||||||
|
init_templatedir(
|
||||||
|
C.CONFIG_FILE, store, target, hook_type='pre-commit',
|
||||||
|
)
|
||||||
|
|
||||||
|
lines = cap_out.get().splitlines()
|
||||||
|
assert len(lines) == 1
|
||||||
|
assert lines[0].startswith('pre-commit installed at')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue