mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-18 00:24:47 +04:00
Split out cmd_output_b
This commit is contained in:
parent
ab063977ad
commit
f612aeb22b
20 changed files with 79 additions and 70 deletions
|
|
@ -21,6 +21,7 @@ from pre_commit.clientlib import META
|
|||
from pre_commit.commands.migrate_config import migrate_config
|
||||
from pre_commit.util import CalledProcessError
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cmd_output_b
|
||||
from pre_commit.util import tmpdir
|
||||
|
||||
|
||||
|
|
@ -38,7 +39,7 @@ def _update_repo(repo_config, store, tags_only):
|
|||
"""
|
||||
with tmpdir() as repo_path:
|
||||
git.init_repo(repo_path, repo_config['repo'])
|
||||
cmd_output('git', 'fetch', 'origin', 'HEAD', '--tags', cwd=repo_path)
|
||||
cmd_output_b('git', 'fetch', 'origin', 'HEAD', '--tags', cwd=repo_path)
|
||||
|
||||
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags')
|
||||
if tags_only:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ from pre_commit import output
|
|||
from pre_commit.clientlib import load_config
|
||||
from pre_commit.repository import all_hooks
|
||||
from pre_commit.repository import install_hook_envs
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import make_executable
|
||||
from pre_commit.util import mkdirp
|
||||
from pre_commit.util import resource_text
|
||||
|
|
@ -117,7 +116,7 @@ def install(
|
|||
overwrite=False, hooks=False,
|
||||
skip_on_missing_config=False, git_dir=None,
|
||||
):
|
||||
if cmd_output('git', 'config', 'core.hooksPath', retcode=None)[1].strip():
|
||||
if git.has_core_hookpaths_set():
|
||||
logger.error(
|
||||
'Cowardly refusing to install hooks with `core.hooksPath` set.\n'
|
||||
'hint: `git config --unset-all core.hooksPath`',
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from pre_commit.output import get_hook_message
|
|||
from pre_commit.repository import all_hooks
|
||||
from pre_commit.repository import install_hook_envs
|
||||
from pre_commit.staged_files_only import staged_files_only
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cmd_output_b
|
||||
from pre_commit.util import noop_context
|
||||
|
||||
|
||||
|
|
@ -117,15 +117,11 @@ def _run_single_hook(classifier, hook, args, skips, cols):
|
|||
)
|
||||
sys.stdout.flush()
|
||||
|
||||
diff_before = cmd_output(
|
||||
'git', 'diff', '--no-ext-diff', retcode=None, encoding=None,
|
||||
)
|
||||
diff_before = cmd_output_b('git', 'diff', '--no-ext-diff', retcode=None)
|
||||
retcode, stdout, stderr = hook.run(
|
||||
tuple(filenames) if hook.pass_filenames else (),
|
||||
)
|
||||
diff_after = cmd_output(
|
||||
'git', 'diff', '--no-ext-diff', retcode=None, encoding=None,
|
||||
)
|
||||
diff_after = cmd_output_b('git', 'diff', '--no-ext-diff', retcode=None)
|
||||
|
||||
file_modifications = diff_before != diff_after
|
||||
|
||||
|
|
@ -235,12 +231,12 @@ def _run_hooks(config, hooks, args, environ):
|
|||
|
||||
|
||||
def _has_unmerged_paths():
|
||||
_, stdout, _ = cmd_output('git', 'ls-files', '--unmerged')
|
||||
_, stdout, _ = cmd_output_b('git', 'ls-files', '--unmerged')
|
||||
return bool(stdout.strip())
|
||||
|
||||
|
||||
def _has_unstaged_config(config_file):
|
||||
retcode, _, _ = cmd_output(
|
||||
retcode, _, _ = cmd_output_b(
|
||||
'git', 'diff', '--no-ext-diff', '--exit-code', config_file,
|
||||
retcode=None,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from pre_commit import output
|
|||
from pre_commit.clientlib import load_manifest
|
||||
from pre_commit.commands.run import run
|
||||
from pre_commit.store import Store
|
||||
from pre_commit.util import cmd_output
|
||||
from pre_commit.util import cmd_output_b
|
||||
from pre_commit.util import tmpdir
|
||||
from pre_commit.xargs import xargs
|
||||
|
||||
|
|
@ -31,8 +31,8 @@ def _repo_ref(tmpdir, repo, ref):
|
|||
logger.warning('Creating temporary repo with uncommitted changes...')
|
||||
|
||||
shadow = os.path.join(tmpdir, 'shadow-repo')
|
||||
cmd_output('git', 'clone', repo, shadow)
|
||||
cmd_output('git', 'checkout', ref, '-b', '_pc_tmp', cwd=shadow)
|
||||
cmd_output_b('git', 'clone', repo, shadow)
|
||||
cmd_output_b('git', 'checkout', ref, '-b', '_pc_tmp', cwd=shadow)
|
||||
|
||||
idx = git.git_path('index', repo=shadow)
|
||||
objs = git.git_path('objects', repo=shadow)
|
||||
|
|
@ -42,7 +42,7 @@ def _repo_ref(tmpdir, repo, ref):
|
|||
if staged_files:
|
||||
xargs(('git', 'add', '--'), staged_files, cwd=repo, env=env)
|
||||
|
||||
cmd_output('git', 'add', '-u', cwd=repo, env=env)
|
||||
cmd_output_b('git', 'add', '-u', cwd=repo, env=env)
|
||||
git.commit(repo=shadow)
|
||||
|
||||
return shadow, git.head_rev(shadow)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue