Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/git_commit_guard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def _load_config(start=None):
config_path = directory / ".commit-guard.toml"
if config_path.exists():
with config_path.open("rb") as f:
return tomllib.load(f)
try:
return tomllib.load(f)
except tomllib.TOMLDecodeError as e:
sys.exit(f"{config_path}: {e}")
return {}


Expand Down
6 changes: 6 additions & 0 deletions tests/test_git_commit_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,12 @@ def test_first_found_wins(self, tmp_path):
(subdir / ".commit-guard.toml").write_text('disable = ["signature"]\n')
assert _load_config(subdir) == {"disable": ["signature"]}

def test_malformed_toml_exits_with_path(self, tmp_path):
config_path = tmp_path / ".commit-guard.toml"
config_path.write_text("disable = [unclosed\n")
with pytest.raises(SystemExit, match=re.escape(str(config_path))):
_load_config(tmp_path)


class TestParseConfigChecks:
def test_disable_list(self):
Expand Down
Loading