docs/gitcredentials: describe URL prefix matching
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>
M Hickford committed
Oct 1, 2025 at 20:56 UTC
fdd21ba116551efb07e784f138d090917b7e70ad
2 files changed
+22
-12
Documentation/gitcredentials.txt
+7
-8
@@ -133,9 +133,8 @@ pattern in the config file. For example, if you have this in your config file:
133
username = foo
134
--------------------------------------
135
136
-then we will match: both protocols are the same, both hosts are the same, and
137
-the "pattern" URL does not care about the path component at all. However, this
138
-context would not match:
136
+then we will match: both protocols are the same and both hosts are the same.
137
+However, this context would not match:
138
139
--------------------------------------
140
[credential "https://kernel.org"]
@@ -149,11 +148,11 @@ match: Git compares the protocols exactly. However, you may use wildcards in
148
the domain name and other pattern matching techniques as with the `http.<URL>.*`
149
options.
150
152
-If the "pattern" URL does include a path component, then this too must match
153
-exactly: the context `https://example.com/bar/baz.git` will match a config
154
-entry for `https://example.com/bar/baz.git` (in addition to matching the config
155
-entry for `https://example.com`) but will not match a config entry for
156
-`https://example.com/bar`.
151
+If the "pattern" URL does include a path component, then this must match
152
+as a prefix path: the context `https://example.com/bar` will match a config
153
+entry for `https://example.com/bar/baz.git` but will not match a config entry for
154
+`https://example.com/other/repo.git` or `https://example.com/barry/repo.git`
155
+(even though it is a string prefix).
156
157
158
CONFIGURATION OPTIONS
t/t0300-credentials.sh
+15
-4
@@ -991,18 +991,24 @@ test_expect_success 'url parser not confused by encoded markers' '
991
992
test_expect_success 'credential config with partial URLs' '
993
echo "echo password=yep" | write_script git-credential-yep &&
994
- test_write_lines url=https://user@example.com/repo.git >stdin &&
994
+ test_write_lines url=https://user@example.com/org/repo.git >stdin &&
995
for partial in \
996
example.com \
997
+ example.com/org/repo.git \
998
user@example.com \
999
+ user@example.com/org/repo.git \
1000
https:// \
1001
https://example.com \
1002
https://example.com/ \
1003
+ https://example.com/org \
1004
+ https://example.com/org/ \
1005
+ https://example.com/org/repo.git \
1006
https://user@example.com \
1007
https://user@example.com/ \
1003
- https://example.com/repo.git \
1004
- https://user@example.com/repo.git \
1005
- /repo.git
1008
+ https://user@example.com/org \
1009
+ https://user@example.com/org/ \
1010
+ https://user@example.com/org/repo.git \
1011
+ /org/repo.git
1012
do
1013
git -c credential.$partial.helper=yep \
1014
credential fill <stdin >stdout &&
@@ -1012,7 +1018,12 @@ test_expect_success 'credential config with partial URLs' '
1018
1019
for partial in \
1020
dont.use.this \
1021
+ example.com/o \
1022
+ user@example.com/o \
1023
http:// \
1024
+ https://example.com/o \
1025
+ https://user@example.com/o \
1026
+ /o \
1027
/repo
1028
do
1029
git -c credential.$partial.helper=yep \