Skip to content

Commit 530dbe6

Browse files
authored
Merge pull request pre-commit#2047 from pre-commit/windows-as-usual
fix pre-commit autoupdate for core.useBuiltinFSMonitor=true on windows
2 parents 2ef29b7 + ab94dd6 commit 530dbe6

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

pre_commit/commands/autoupdate.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,36 @@ def from_config(cls, config: Dict[str, Any]) -> 'RevInfo':
3636
return cls(config['repo'], config['rev'], None)
3737

3838
def update(self, tags_only: bool, freeze: bool) -> 'RevInfo':
39+
git_cmd = ('git', *git.NO_FS_MONITOR)
40+
3941
if tags_only:
40-
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--abbrev=0')
42+
tag_cmd = (
43+
*git_cmd, 'describe',
44+
'FETCH_HEAD', '--tags', '--abbrev=0',
45+
)
4146
else:
42-
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--exact')
47+
tag_cmd = (
48+
*git_cmd, 'describe',
49+
'FETCH_HEAD', '--tags', '--exact',
50+
)
4351

4452
with tmpdir() as tmp:
4553
git.init_repo(tmp, self.repo)
46-
cmd_output_b('git', 'fetch', 'origin', 'HEAD', '--tags', cwd=tmp)
54+
cmd_output_b(
55+
*git_cmd, 'fetch', 'origin', 'HEAD', '--tags',
56+
cwd=tmp,
57+
)
4758

4859
try:
4960
rev = cmd_output(*tag_cmd, cwd=tmp)[1].strip()
5061
except CalledProcessError:
51-
cmd = ('git', 'rev-parse', 'FETCH_HEAD')
62+
cmd = (*git_cmd, 'rev-parse', 'FETCH_HEAD')
5263
rev = cmd_output(*cmd, cwd=tmp)[1].strip()
5364

5465
frozen = None
5566
if freeze:
56-
exact = cmd_output('git', 'rev-parse', rev, cwd=tmp)[1].strip()
67+
exact_rev_cmd = (*git_cmd, 'rev-parse', rev)
68+
exact = cmd_output(*exact_rev_cmd, cwd=tmp)[1].strip()
5769
if exact != rev:
5870
rev, frozen = exact, rev
5971
return self._replace(rev=rev, frozen=frozen)

pre_commit/git.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
from pre_commit.util import cmd_output
1313
from pre_commit.util import cmd_output_b
1414

15-
1615
logger = logging.getLogger(__name__)
1716

17+
# see #2046
18+
NO_FS_MONITOR = ('-c', 'core.useBuiltinFSMonitor=false')
19+
1820

1921
def zsplit(s: str) -> List[str]:
2022
s = s.strip('\0')
@@ -185,10 +187,11 @@ def init_repo(path: str, remote: str) -> None:
185187
if os.path.isdir(remote):
186188
remote = os.path.abspath(remote)
187189

190+
git = ('git', *NO_FS_MONITOR)
188191
env = no_git_env()
189192
# avoid the user's template so that hooks do not recurse
190-
cmd_output_b('git', 'init', '--template=', path, env=env)
191-
cmd_output_b('git', 'remote', 'add', 'origin', remote, cwd=path, env=env)
193+
cmd_output_b(*git, 'init', '--template=', path, env=env)
194+
cmd_output_b(*git, 'remote', 'add', 'origin', remote, cwd=path, env=env)
192195

193196

194197
def commit(repo: str = '.') -> None:

tests/commands/autoupdate_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import yaml
66

77
import pre_commit.constants as C
8+
from pre_commit import envcontext
89
from pre_commit import git
910
from pre_commit import util
1011
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):
176177
assert cfg.read() == fmt.format(out_of_date.path, out_of_date.head_rev)
177178

178179

180+
def test_autoupdate_with_core_useBuiltinFSMonitor(out_of_date, tmpdir, store):
181+
# force the setting on "globally" for git
182+
home = tmpdir.join('fakehome').ensure_dir()
183+
home.join('.gitconfig').write('[core]\nuseBuiltinFSMonitor = true\n')
184+
with envcontext.envcontext((('HOME', str(home)),)):
185+
test_autoupdate_out_of_date_repo(out_of_date, tmpdir, store)
186+
187+
179188
def test_autoupdate_pure_yaml(out_of_date, tmpdir, store):
180189
with mock.patch.object(util, 'Dumper', yaml.SafeDumper):
181190
test_autoupdate_out_of_date_repo(out_of_date, tmpdir, store)

0 commit comments

Comments
 (0)