]> git.ipfire.org Git - thirdparty/git.git/commitdiff
docs/gitcredentials: describe URL prefix matching
authorM Hickford <mirth.hickford@gmail.com>
Wed, 1 Oct 2025 20:56:49 +0000 (20:56 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Oct 2025 21:23:51 +0000 (14:23 -0700)
Documentation was inaccurate since 9a121b0d226 (credential: handle
`credential.<partial-URL>.<key>` again, 2020-04-24)

Add tests for documented behaviour.

Signed-off-by: M Hickford <mirth.hickford@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/gitcredentials.txt
t/t0300-credentials.sh

index 35a7452c8fe3cca7e972483f279adcc80b7c91da..931a33f8385830a642e4db89aae0ded1859a2a8b 100644 (file)
@@ -133,9 +133,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"]
@@ -149,11 +148,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.<URL>.*`
 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
index cb3a85c7ff1bcc508d4c0f2d83c97263905908e7..07aa834d33e248c8703e3cf2ff85bed0e4d1439d 100755 (executable)
@@ -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 <stdin >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 \