Files
pre-commit/pre_commit/hooks_workspace.py
2014-03-13 19:36:44 -07:00

20 lines
512 B
Python

import contextlib
import os.path
from plumbum import local
import pre_commit.constants as C
from pre_commit import git
def get_pre_commit_dir_path():
return os.path.join(git.get_root(), C.HOOKS_WORKSPACE)
@contextlib.contextmanager
def in_hooks_workspace():
"""Change into the hooks workspace. If it does not exist create it."""
if not os.path.exists(get_pre_commit_dir_path()):
local.path(get_pre_commit_dir_path()).mkdir()
with local.cwd(get_pre_commit_dir_path()):
yield