Skip to content

Commit 3a19184

Browse files
committed
Add option to run_repo_helper to disable pre-commit, for use in tests.
1 parent 1b872b3 commit 3a19184

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

repo_helper/cli/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ def commit_changed_files(
101101
commit = confirm("Commit?", default=True)
102102

103103
if commit:
104-
# Ensure the working directory for pre-commit is correct
105-
r.hooks["pre-commit"].cwd = str(repo_path.absolute()) # type: ignore
104+
if enable_pre_commit or "pre-commit" in r.hooks:
105+
# Ensure the working directory for pre-commit is correct
106+
r.hooks["pre-commit"].cwd = str(repo_path.absolute()) # type: ignore
106107

107108
try:
108109
commit_id = commit_changes(r, message.decode("UTF-8"))
@@ -125,6 +126,7 @@ def run_repo_helper(
125126
initialise: bool,
126127
commit: Optional[bool],
127128
message: str,
129+
enable_pre_commit: bool = True,
128130
) -> int:
129131
"""
130132
Run repo_helper.
@@ -134,6 +136,7 @@ def run_repo_helper(
134136
:param initialise: Whether to initialise the repository.
135137
:param commit: Whether to commit unchanged files.
136138
:param message: The commit message.
139+
:param enable_pre_commit: Whether to install and configure pre-commit. Default :py:obj`True`.
137140
"""
138141

139142
# this package
@@ -166,6 +169,7 @@ def run_repo_helper(
166169
managed_files=managed_files,
167170
commit=commit,
168171
message=message.encode("UTF-8"),
172+
enable_pre_commit=enable_pre_commit,
169173
)
170174
except CommitError as e:
171175
indented_error = '\n'.join(f"\t{line}" for line in textwrap.wrap(str(e)))

tests/test_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def test_via_run_repo_helper(
4949
initialise=True,
5050
commit=True,
5151
message="Testing Testing",
52+
enable_pre_commit=False,
5253
) == 0
5354

5455
stat = status(temp_empty_repo.path)

0 commit comments

Comments
 (0)