Skip to content

Commit ac21ff9

Browse files
committed
fix: replace invalid config key scriv.user_nick with scriv.user-nick #130
1 parent 7be87f2 commit ac21ff9

File tree

7 files changed

+59
-3
lines changed

7 files changed

+59
-3
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Contributions are very welcome. Thanks to all the contributors so far:
6666
| James Gerity
6767
| Javier Sagredo
6868
| Kurt McKee
69+
| Mark Dickinson
6970
| Matias Guijarro
7071
| Michael Makukha
7172
| Rodrigo Girão Serrão
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Fixed
2+
.....
3+
4+
- Replaced the invalid GitHub config key ``scriv.user_nick`` with
5+
``scriv.user-nick``. Fixes `issue 130`_.
6+
Thanks, `Mark Dickinson <pull 131_>`_.
7+
8+
.. _issue 130: https://github.com/nedbat/scriv/issues/130
9+
.. _pull 131: https://github.com/nedbat/scriv/pull/131/files

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ Thanks to all the contributors so far:
8888
| James Gerity
8989
| Javier Sagredo
9090
| Kurt McKee
91+
| Mark Dickinson
9192
| Matias Guijarro
9293
| Michael Makukha
9394
| Rodrigo Girão Serrão
9495
| Ronny Pfannschmidt
9596
96-
.. [[[end]]] (checksum: 69c390284832f0854ceb4ef0a1f1042c)
97+
.. [[[end]]] (checksum: 38a9f227f719032ff5b67bcc50bb7276)
9798
9899
.. _repo: https://github.com/nedbat/scriv
99100

src/scriv/gitinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def user_nick() -> str:
1818
"""
1919
Get a short name for the current user.
2020
"""
21-
nick = git_config("scriv.user_nick")
21+
nick = git_config("scriv.user-nick")
2222
if nick:
2323
return nick
2424

tests/faker.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Fake implementations of some of our external information sources."""
22

3+
import re
34
import shlex
45
from collections.abc import Iterable
56
from typing import Callable, Optional
@@ -10,6 +11,11 @@
1011
CmdHandler = Callable[[list[str]], CmdResult]
1112

1213

14+
# A regex to help with catching some (but not all) invalid Git config keys.
15+
WORD = r"[a-zA-Z][a-zA-Z0-9-]*"
16+
GIT_CONFIG_KEY = rf"{WORD}(\..*)?\.{WORD}"
17+
18+
1319
class FakeRunCommand:
1420
"""
1521
A fake implementation of run_command.
@@ -88,6 +94,8 @@ def run_command(self, argv: list[str]) -> CmdResult:
8894

8995
def set_config(self, name: str, value: str) -> None:
9096
"""Set a fake Git configuration value."""
97+
if re.fullmatch(GIT_CONFIG_KEY, name) is None:
98+
raise ValueError(f"invalid key: {name!r}")
9199
self.config[name] = value
92100

93101
def set_branch(self, branch_name: str) -> None:

tests/test_faker.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
Mostly error paths, since the happy paths are covered by other tests.
55
"""
66

7+
import re
8+
9+
import pytest
10+
711
from scriv import shell
812

913

@@ -23,3 +27,36 @@ def test_no_such_git_command(fake_git):
2327
False,
2428
"no fake git command: ['git', 'config', '--wut']",
2529
)
30+
31+
32+
@pytest.mark.parametrize(
33+
"name",
34+
[
35+
"foo.bar",
36+
"foo.bar12",
37+
"foo.bar-",
38+
"foo.bar-bar",
39+
"foo-foo.bar",
40+
"section.subsection.bar",
41+
"section.some/sub_section!ok.bar",
42+
],
43+
)
44+
def test_git_set_config_good_names(name, fake_git):
45+
val = "xyzzy plugh!?"
46+
fake_git.set_config(name, val)
47+
result = shell.run_command(f"git config --get {name}")
48+
assert result == (True, val + "\n")
49+
50+
51+
@pytest.mark.parametrize(
52+
"name",
53+
[
54+
"bar",
55+
"foo.12bar",
56+
"foo.bar_bar",
57+
"foo_foo.bar",
58+
],
59+
)
60+
def test_git_set_config_bad_names(name, fake_git):
61+
with pytest.raises(ValueError, match=re.escape(f"invalid key: {name!r}")):
62+
fake_git.set_config(name, "hello there")

tests/test_gitinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def test_user_nick_from_scriv_user_nick(fake_git):
9-
fake_git.set_config("scriv.user_nick", "joedev")
9+
fake_git.set_config("scriv.user-nick", "joedev")
1010
assert user_nick() == "joedev"
1111

1212

0 commit comments

Comments
 (0)