Skip to content

Commit 5252136

Browse files
codexByron
authored andcommitted
Address review feedback about config section casing
Review feedback: Git accepts core section names case-insensitively, while GitConfigParser preserves section casing and the hook lookup only inspected a literal core section. Aggregate options from every section whose name case-folds to core before selecting the effective hooksPath value. Extend the regression configuration to use mixed casing for both the section and option names.
1 parent fafbdc8 commit 5252136

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

git/index/fun.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def hook_path(name: str, git_dir: PathLike) -> str:
6767
def _commit_hook_path(name: str, index: "IndexFile") -> str:
6868
""":return: path to the named commit hook, respecting Git's core.hooksPath."""
6969
with index.repo.config_reader() as config:
70-
core_items = config.items("core") if config.has_section("core") else []
70+
core_items = [
71+
item for section in config.sections() if section.lower() == "core" for item in config.items(section)
72+
]
7173
hooks_dir = next((value for option, value in reversed(core_items) if option.lower() == "hookspath"), None)
7274

7375
if not hooks_dir:

test/test_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ def test_pre_commit_hook_respects_core_hooks_path(self, rw_repo):
12061206
os.chmod(hp, 0o744)
12071207

12081208
with index.repo.config_writer() as writer:
1209-
writer.set_value("core", "HoOkSpAtH", "custom-hooks")
1209+
writer.set_value("CoRe", "HoOkSpAtH", "custom-hooks")
12101210

12111211
index.commit("This should run the custom hook")
12121212
output = Path(rw_repo.working_dir, "custom-hook-output.txt").read_text(encoding="utf-8")

0 commit comments

Comments
 (0)