mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 13:00:10 -06:00
Merge pull request #714 from pre-commit/remove_cwd_fn
Move cwd() to tests-only
This commit is contained in:
@@ -18,7 +18,6 @@ from pre_commit.commands.migrate_config import migrate_config
|
||||
from pre_commit.repository import Repository
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
|
||||
|
||||
class RepositoryCannotBeUpdatedError(RuntimeError):
|
||||
@@ -35,17 +34,17 @@ def _update_repo(repo_config, runner, tags_only):
|
||||
"""
|
||||
repo_path = runner.store.clone(repo_config['repo'], repo_config['sha'])
|
||||
|
||||
with cwd(repo_path):
|
||||
cmd_output('git', 'fetch')
|
||||
tag_cmd = ('git', 'describe', 'origin/master', '--tags')
|
||||
if tags_only:
|
||||
tag_cmd += ('--abbrev=0',)
|
||||
else:
|
||||
tag_cmd += ('--exact',)
|
||||
try:
|
||||
rev = cmd_output(*tag_cmd)[1].strip()
|
||||
except CalledProcessError:
|
||||
rev = cmd_output('git', 'rev-parse', 'origin/master')[1].strip()
|
||||
cmd_output('git', '-C', repo_path, 'fetch')
|
||||
tag_cmd = ('git', '-C', repo_path, 'describe', 'origin/master', '--tags')
|
||||
if tags_only:
|
||||
tag_cmd += ('--abbrev=0',)
|
||||
else:
|
||||
tag_cmd += ('--exact',)
|
||||
try:
|
||||
rev = cmd_output(*tag_cmd)[1].strip()
|
||||
except CalledProcessError:
|
||||
tag_cmd = ('git', '-C', repo_path, 'rev-parse', 'origin/master')
|
||||
rev = cmd_output(*tag_cmd)[1].strip()
|
||||
|
||||
# Don't bother trying to update if our sha is the same
|
||||
if rev == repo_config['sha']:
|
||||
|
||||
@@ -8,7 +8,6 @@ import tarfile
|
||||
|
||||
from pre_commit import output
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.util import resource_filename
|
||||
from pre_commit.util import rmtree
|
||||
from pre_commit.util import tmpdir
|
||||
@@ -42,8 +41,7 @@ def make_archive(name, repo, ref, destdir):
|
||||
with tmpdir() as tempdir:
|
||||
# Clone the repository to the temporary directory
|
||||
cmd_output('git', 'clone', repo, tempdir)
|
||||
with cwd(tempdir):
|
||||
cmd_output('git', 'checkout', ref)
|
||||
cmd_output('git', '-C', tempdir, 'checkout', ref)
|
||||
|
||||
# We don't want the '.git' directory
|
||||
# It adds a bunch of size to the archive and we don't use it at
|
||||
|
||||
@@ -14,7 +14,6 @@ from pre_commit import file_lock
|
||||
from pre_commit.util import clean_path_on_failure
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import copy_tree_to_path
|
||||
from pre_commit.util import cwd
|
||||
from pre_commit.util import no_git_env
|
||||
from pre_commit.util import resource_filename
|
||||
|
||||
@@ -142,16 +141,14 @@ class Store(object):
|
||||
def clone(self, repo, ref, deps=()):
|
||||
"""Clone the given url and checkout the specific ref."""
|
||||
def clone_strategy(directory):
|
||||
cmd_output(
|
||||
'git', 'clone', '--no-checkout', repo, directory,
|
||||
env=no_git_env(),
|
||||
)
|
||||
with cwd(directory):
|
||||
cmd_output('git', 'reset', ref, '--hard', env=no_git_env())
|
||||
cmd_output(
|
||||
'git', 'submodule', 'update', '--init', '--recursive',
|
||||
env=no_git_env(),
|
||||
)
|
||||
env = no_git_env()
|
||||
|
||||
def _git_cmd(*args):
|
||||
return cmd_output('git', '-C', directory, *args, env=env)
|
||||
|
||||
_git_cmd('clone', '--no-checkout', repo, '.')
|
||||
_git_cmd('reset', ref, '--hard')
|
||||
_git_cmd('submodule', 'update', '--init', '--recursive')
|
||||
|
||||
return self._new_repo(repo, ref, deps, clone_strategy)
|
||||
|
||||
|
||||
@@ -16,16 +16,6 @@ from pre_commit import five
|
||||
from pre_commit import parse_shebang
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def cwd(path):
|
||||
original_cwd = os.getcwd()
|
||||
os.chdir(path)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
os.chdir(original_cwd)
|
||||
|
||||
|
||||
def mkdirp(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
|
||||
Reference in New Issue
Block a user