mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
fix pre-commit autoupdate for core.useBuiltinFSMonitor=true on windows
This commit is contained in:
parent
2ef29b7f95
commit
ab94dd69f8
3 changed files with 32 additions and 8 deletions
|
|
@ -36,24 +36,36 @@ class RevInfo(NamedTuple):
|
||||||
return cls(config['repo'], config['rev'], None)
|
return cls(config['repo'], config['rev'], None)
|
||||||
|
|
||||||
def update(self, tags_only: bool, freeze: bool) -> 'RevInfo':
|
def update(self, tags_only: bool, freeze: bool) -> 'RevInfo':
|
||||||
|
git_cmd = ('git', *git.NO_FS_MONITOR)
|
||||||
|
|
||||||
if tags_only:
|
if tags_only:
|
||||||
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--abbrev=0')
|
tag_cmd = (
|
||||||
|
*git_cmd, 'describe',
|
||||||
|
'FETCH_HEAD', '--tags', '--abbrev=0',
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--exact')
|
tag_cmd = (
|
||||||
|
*git_cmd, 'describe',
|
||||||
|
'FETCH_HEAD', '--tags', '--exact',
|
||||||
|
)
|
||||||
|
|
||||||
with tmpdir() as tmp:
|
with tmpdir() as tmp:
|
||||||
git.init_repo(tmp, self.repo)
|
git.init_repo(tmp, self.repo)
|
||||||
cmd_output_b('git', 'fetch', 'origin', 'HEAD', '--tags', cwd=tmp)
|
cmd_output_b(
|
||||||
|
*git_cmd, 'fetch', 'origin', 'HEAD', '--tags',
|
||||||
|
cwd=tmp,
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rev = cmd_output(*tag_cmd, cwd=tmp)[1].strip()
|
rev = cmd_output(*tag_cmd, cwd=tmp)[1].strip()
|
||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
cmd = ('git', 'rev-parse', 'FETCH_HEAD')
|
cmd = (*git_cmd, 'rev-parse', 'FETCH_HEAD')
|
||||||
rev = cmd_output(*cmd, cwd=tmp)[1].strip()
|
rev = cmd_output(*cmd, cwd=tmp)[1].strip()
|
||||||
|
|
||||||
frozen = None
|
frozen = None
|
||||||
if freeze:
|
if freeze:
|
||||||
exact = cmd_output('git', 'rev-parse', rev, cwd=tmp)[1].strip()
|
exact_rev_cmd = (*git_cmd, 'rev-parse', rev)
|
||||||
|
exact = cmd_output(*exact_rev_cmd, cwd=tmp)[1].strip()
|
||||||
if exact != rev:
|
if exact != rev:
|
||||||
rev, frozen = exact, rev
|
rev, frozen = exact, rev
|
||||||
return self._replace(rev=rev, frozen=frozen)
|
return self._replace(rev=rev, frozen=frozen)
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,11 @@ from pre_commit.util import CalledProcessError
|
||||||
from pre_commit.util import cmd_output
|
from pre_commit.util import cmd_output
|
||||||
from pre_commit.util import cmd_output_b
|
from pre_commit.util import cmd_output_b
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
# see #2046
|
||||||
|
NO_FS_MONITOR = ('-c', 'core.useBuiltinFSMonitor=false')
|
||||||
|
|
||||||
|
|
||||||
def zsplit(s: str) -> List[str]:
|
def zsplit(s: str) -> List[str]:
|
||||||
s = s.strip('\0')
|
s = s.strip('\0')
|
||||||
|
|
@ -185,10 +187,11 @@ def init_repo(path: str, remote: str) -> None:
|
||||||
if os.path.isdir(remote):
|
if os.path.isdir(remote):
|
||||||
remote = os.path.abspath(remote)
|
remote = os.path.abspath(remote)
|
||||||
|
|
||||||
|
git = ('git', *NO_FS_MONITOR)
|
||||||
env = no_git_env()
|
env = no_git_env()
|
||||||
# avoid the user's template so that hooks do not recurse
|
# avoid the user's template so that hooks do not recurse
|
||||||
cmd_output_b('git', 'init', '--template=', path, env=env)
|
cmd_output_b(*git, 'init', '--template=', path, env=env)
|
||||||
cmd_output_b('git', 'remote', 'add', 'origin', remote, cwd=path, env=env)
|
cmd_output_b(*git, 'remote', 'add', 'origin', remote, cwd=path, env=env)
|
||||||
|
|
||||||
|
|
||||||
def commit(repo: str = '.') -> None:
|
def commit(repo: str = '.') -> None:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import pytest
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
import pre_commit.constants as C
|
import pre_commit.constants as C
|
||||||
|
from pre_commit import envcontext
|
||||||
from pre_commit import git
|
from pre_commit import git
|
||||||
from pre_commit import util
|
from pre_commit import util
|
||||||
from pre_commit.commands.autoupdate import _check_hooks_still_exist_at_rev
|
from pre_commit.commands.autoupdate import _check_hooks_still_exist_at_rev
|
||||||
|
|
@ -176,6 +177,14 @@ def test_autoupdate_out_of_date_repo(out_of_date, tmpdir, store):
|
||||||
assert cfg.read() == fmt.format(out_of_date.path, out_of_date.head_rev)
|
assert cfg.read() == fmt.format(out_of_date.path, out_of_date.head_rev)
|
||||||
|
|
||||||
|
|
||||||
|
def test_autoupdate_with_core_useBuiltinFSMonitor(out_of_date, tmpdir, store):
|
||||||
|
# force the setting on "globally" for git
|
||||||
|
home = tmpdir.join('fakehome').ensure_dir()
|
||||||
|
home.join('.gitconfig').write('[core]\nuseBuiltinFSMonitor = true\n')
|
||||||
|
with envcontext.envcontext((('HOME', str(home)),)):
|
||||||
|
test_autoupdate_out_of_date_repo(out_of_date, tmpdir, store)
|
||||||
|
|
||||||
|
|
||||||
def test_autoupdate_pure_yaml(out_of_date, tmpdir, store):
|
def test_autoupdate_pure_yaml(out_of_date, tmpdir, store):
|
||||||
with mock.patch.object(util, 'Dumper', yaml.SafeDumper):
|
with mock.patch.object(util, 'Dumper', yaml.SafeDumper):
|
||||||
test_autoupdate_out_of_date_repo(out_of_date, tmpdir, store)
|
test_autoupdate_out_of_date_repo(out_of_date, tmpdir, store)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue