From 9cdd8b989d78233f9bf293670759c6989324d9af Mon Sep 17 00:00:00 2001 From: Daniele Tentoni Date: Wed, 15 Oct 2025 00:15:00 +0200 Subject: [PATCH] feat: introduce new ${path} var to address the entire subpath of the repo url --- README.md | 9 +++++++- passgithelper.py | 3 +++ test_data/wildcard_path/git-pass-mapping.ini | 2 ++ test_passgithelper.py | 23 ++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test_data/wildcard_path/git-pass-mapping.ini diff --git a/README.md b/README.md index 3edbaec..f7b7322 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,14 @@ target=git-logins/${host} 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. -Apart from `${host}`, the variables `${username}` and `${protocol}` can be used for replacements. +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: + +| var | value | +| --- | --- | +| `${host}` | `github.com` | +| `${username}` | `languitar` | +| `${path}` | `languitar/pass-git-helper.git` | +| `${protocol}` | `https` | #### DEFAULT Section diff --git a/passgithelper.py b/passgithelper.py index 152daf6..14abda3 100755 --- a/passgithelper.py +++ b/passgithelper.py @@ -369,6 +369,9 @@ def define_pass_target( ) -> str: """Determine the pass target by filling in potentially used variables.""" pass_target = section["target"].replace("${host}", request["host"]) + + if "path" in request: + pass_target = pass_target.replace("${path}", request["path"]) if "username" in request: pass_target = pass_target.replace("${username}", request["username"]) if "protocol" in request: diff --git a/test_data/wildcard_path/git-pass-mapping.ini b/test_data/wildcard_path/git-pass-mapping.ini new file mode 100644 index 0000000..abc6b67 --- /dev/null +++ b/test_data/wildcard_path/git-pass-mapping.ini @@ -0,0 +1,2 @@ +[*] +target=dev/${protocol}/${host}/${username}/${path} diff --git a/test_passgithelper.py b/test_passgithelper.py index da8ef27..8a16b60 100644 --- a/test_passgithelper.py +++ b/test_passgithelper.py @@ -342,6 +342,29 @@ def test_wildcard_matching(self, capsys: Any) -> None: out, _ = capsys.readouterr() assert out == "password=narf-wildcard\n" + @pytest.mark.parametrize( + "helper_config", + [ + HelperConfig( + "test_data/wildcard_path", + """ +protocol=https +host=path_wildcard.com +username=path_wildcard +path=subpath/bar.git""", + b"daniele-tentoni-path-wildcard", + "dev/https/path_wildcard.com/path_wildcard/subpath/bar.git", + ), + ], + indirect=True, + ) + @pytest.mark.usefixtures("helper_config") + def test_wildcard_path_matching(self, capsys: Any) -> None: + passgithelper.main(["get"]) + + out, _ = capsys.readouterr() + assert out == "password=daniele-tentoni-path-wildcard\n" + @pytest.mark.parametrize( "helper_config", [