From 15f44a2ac5658ac41cbed036f182d506e377022a Mon Sep 17 00:00:00 2001 From: M Hickford Date: Tue, 30 Sep 2025 22:30:20 +0100 Subject: [PATCH 1/2] docs/gitcredentials: describe URL prefix matching Documentation was inaccurate since 9a121b0d226 (credential: handle `credential..` again, 2020-04-24) Add tests for documented behaviour. Signed-off-by: M Hickford --- Documentation/gitcredentials.adoc | 15 +++++++-------- t/t0300-credentials.sh | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Documentation/gitcredentials.adoc b/Documentation/gitcredentials.adoc index 3337bb475de4c5..60c2cc4adefd77 100644 --- a/Documentation/gitcredentials.adoc +++ b/Documentation/gitcredentials.adoc @@ -150,9 +150,8 @@ pattern in the config file. For example, if you have this in your config file: username = foo -------------------------------------- -then we will match: both protocols are the same, both hosts are the same, and -the "pattern" URL does not care about the path component at all. However, this -context would not match: +then we will match: both protocols are the same and both hosts are the same. +However, this context would not match: -------------------------------------- [credential "https://kernel.org"] @@ -166,11 +165,11 @@ match: Git compares the protocols exactly. However, you may use wildcards in the domain name and other pattern matching techniques as with the `http..*` options. -If the "pattern" URL does include a path component, then this too must match -exactly: the context `https://example.com/bar/baz.git` will match a config -entry for `https://example.com/bar/baz.git` (in addition to matching the config -entry for `https://example.com`) but will not match a config entry for -`https://example.com/bar`. +If the "pattern" URL does include a path component, then this must match +as a prefix path: the context `https://example.com/bar` will match a config +entry for `https://example.com/bar/baz.git` but will not match a config entry for +`https://example.com/other/repo.git` or `https://example.com/barry/repo.git` +(even though it is a string prefix). CONFIGURATION OPTIONS diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh index cb3a85c7ff1bcc..07aa834d33e248 100755 --- a/t/t0300-credentials.sh +++ b/t/t0300-credentials.sh @@ -991,18 +991,24 @@ test_expect_success 'url parser not confused by encoded markers' ' test_expect_success 'credential config with partial URLs' ' echo "echo password=yep" | write_script git-credential-yep && - test_write_lines url=https://user@example.com/repo.git >stdin && + test_write_lines url=https://user@example.com/org/repo.git >stdin && for partial in \ example.com \ + example.com/org/repo.git \ user@example.com \ + user@example.com/org/repo.git \ https:// \ https://example.com \ https://example.com/ \ + https://example.com/org \ + https://example.com/org/ \ + https://example.com/org/repo.git \ https://user@example.com \ https://user@example.com/ \ - https://example.com/repo.git \ - https://user@example.com/repo.git \ - /repo.git + https://user@example.com/org \ + https://user@example.com/org/ \ + https://user@example.com/org/repo.git \ + /org/repo.git do git -c credential.$partial.helper=yep \ credential fill stdout && @@ -1012,7 +1018,12 @@ test_expect_success 'credential config with partial URLs' ' for partial in \ dont.use.this \ + example.com/o \ + user@example.com/o \ http:// \ + https://example.com/o \ + https://user@example.com/o \ + /o \ /repo do git -c credential.$partial.helper=yep \ From 7e22060c411688d0c3cf750050bac3bea46c3815 Mon Sep 17 00:00:00 2001 From: M Hickford Date: Sat, 4 Oct 2025 13:53:24 +0100 Subject: [PATCH 2/2] docs/gitcredentials: further describe path prefix Record that path prefix matching requires the pattern to also include protocol and host. Signed-off-by: M Hickford --- Documentation/gitcredentials.adoc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/gitcredentials.adoc b/Documentation/gitcredentials.adoc index 60c2cc4adefd77..bf595f791843f8 100644 --- a/Documentation/gitcredentials.adoc +++ b/Documentation/gitcredentials.adoc @@ -166,10 +166,11 @@ the domain name and other pattern matching techniques as with the `http..*` options. If the "pattern" URL does include a path component, then this must match -as a prefix path: the context `https://example.com/bar` will match a config +as a path prefix: the context `https://example.com/bar` will match a config entry for `https://example.com/bar/baz.git` but will not match a config entry for `https://example.com/other/repo.git` or `https://example.com/barry/repo.git` -(even though it is a string prefix). +(even though it is a string prefix). To match as a prefix, the pattern +must include protocol and host. CONFIGURATION OPTIONS