Repository: asottile/babi

Issue:
pre-commit runs with the wrong configuration when accessing a file in a different repository
went through all the trouble to check the right config exists here: https://github.com/asottile/babi/blob/5cf5f2501c90274e7f640ff0ad4dfb355631b960/babi/linters/pre_commit.py#L66

but then didn't bother actually using it here: https://github.com/asottile/babi/blob/5cf5f2501c90274e7f640ff0ad4dfb355631b960/babi/linters/pre_commit.py#L69

Discussion:

Patch:
diff --git a/babi/linters/pre_commit.py b/babi/linters/pre_commit.py
index d5ffc5c..380608b 100644
--- a/babi/linters/pre_commit.py
+++ b/babi/linters/pre_commit.py
@@ -63,10 +63,16 @@ class PreCommit:
             return None  # not in a git repo!
 
         # no pre-commit config!
-        if not os.path.exists(os.path.join(root, '.pre-commit-config.yaml')):
+        cfg = os.path.join(root, '.pre-commit-config.yaml')
+        if not os.path.exists(cfg):
             return None
 
-        return ('pre-commit', 'run', '--color=never', '--files', filename)
+        return (
+            'pre-commit', 'run',
+            '--color=never',
+            '--config', cfg,
+            '--files', filename,
+        )
 
     def parse(self, filename: str, output: str) -> tuple[linting.Error, ...]:
         root = self._root(filename)


Test patch:
diff --git a/tests/linters/pre_commit_test.py b/tests/linters/pre_commit_test.py
index 6fdf20a..7fa7781 100644
--- a/tests/linters/pre_commit_test.py
+++ b/tests/linters/pre_commit_test.py
@@ -96,10 +96,16 @@ def test_command_returns_none_no_pre_commit_config(tmpdir_git):
 
 
 def test_command_returns_when_config_exists(tmpdir_git):
-    tmpdir_git.join('.pre-commit-config.yaml').write('{}\n')
+    cfg = tmpdir_git.join('.pre-commit-config.yaml')
+    cfg.write('{}\n')
     path = str(tmpdir_git.join('t.py'))
     ret = PreCommit().command(path, 'source.python')
-    assert ret == ('pre-commit', 'run', '--color=never', '--files', path)
+    assert ret == (
+        'pre-commit', 'run',
+        '--color=never',
+        '--config', str(cfg),
+        '--files', path,
+    )
 
 
 def test_filters_file_paths_to_actual_file(tmpdir_git):