Skip to content

Commit 9cdd8b9

Browse files
feat: introduce new ${path} var to address the entire subpath of the repo url
1 parent d7550ca commit 9cdd8b9

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,14 @@ target=git-logins/${host}
138138

139139
The above configuration directive will lead to any host that did not match any previous section in the ini file to being looked up under the `git-logins` directory in your password store.
140140

141-
Apart from `${host}`, the variables `${username}` and `${protocol}` can be used for replacements.
141+
Apart from `${host}`, the variables `${username}`, `${path}` and `${protocol}` can be used for replacements. Given the remote url `https://github.com/languitar/pass-git-helper.git`, variables are filled as follow:
142+
143+
| var | value |
144+
| --- | --- |
145+
| `${host}` | `github.com` |
146+
| `${username}` | `languitar` |
147+
| `${path}` | `languitar/pass-git-helper.git` |
148+
| `${protocol}` | `https` |
142149

143150
#### DEFAULT Section
144151

passgithelper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ def define_pass_target(
369369
) -> str:
370370
"""Determine the pass target by filling in potentially used variables."""
371371
pass_target = section["target"].replace("${host}", request["host"])
372+
373+
if "path" in request:
374+
pass_target = pass_target.replace("${path}", request["path"])
372375
if "username" in request:
373376
pass_target = pass_target.replace("${username}", request["username"])
374377
if "protocol" in request:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*]
2+
target=dev/${protocol}/${host}/${username}/${path}

test_passgithelper.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,29 @@ def test_wildcard_matching(self, capsys: Any) -> None:
342342
out, _ = capsys.readouterr()
343343
assert out == "password=narf-wildcard\n"
344344

345+
@pytest.mark.parametrize(
346+
"helper_config",
347+
[
348+
HelperConfig(
349+
"test_data/wildcard_path",
350+
"""
351+
protocol=https
352+
host=path_wildcard.com
353+
username=path_wildcard
354+
path=subpath/bar.git""",
355+
b"daniele-tentoni-path-wildcard",
356+
"dev/https/path_wildcard.com/path_wildcard/subpath/bar.git",
357+
),
358+
],
359+
indirect=True,
360+
)
361+
@pytest.mark.usefixtures("helper_config")
362+
def test_wildcard_path_matching(self, capsys: Any) -> None:
363+
passgithelper.main(["get"])
364+
365+
out, _ = capsys.readouterr()
366+
assert out == "password=daniele-tentoni-path-wildcard\n"
367+
345368
@pytest.mark.parametrize(
346369
"helper_config",
347370
[

0 commit comments

Comments
 (0)