Skip to content

Commit 4b64cf4

Browse files
committed
docs/gitcredentials: describe URL prefix matching
Documentation was inaccurate since 9a121b0 (credential: handle `credential.<partial-URL>.<key>` again, 2020-04-24) Add tests for documented behaviour. Signed-off-by: M Hickford <[email protected]>
1 parent 821f583 commit 4b64cf4

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

Documentation/gitcredentials.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ pattern in the config file. For example, if you have this in your config file:
150150
username = foo
151151
--------------------------------------
152152
153-
then we will match: both protocols are the same, both hosts are the same, and
154-
the "pattern" URL does not care about the path component at all. However, this
155-
context would not match:
153+
then we will match: both protocols are the same and both hosts are the same.
154+
However, this context would not match:
156155
157156
--------------------------------------
158157
[credential "https://kernel.org"]
@@ -166,11 +165,12 @@ match: Git compares the protocols exactly. However, you may use wildcards in
166165
the domain name and other pattern matching techniques as with the `http.<URL>.*`
167166
options.
168167
169-
If the "pattern" URL does include a path component, then this too must match
170-
exactly: the context `https://example.com/bar/baz.git` will match a config
171-
entry for `https://example.com/bar/baz.git` (in addition to matching the config
172-
entry for `https://example.com`) but will not match a config entry for
173-
`https://example.com/bar`.
168+
If the "pattern" URL does include a path component, then this must match
169+
as a path prefix: the context `https://example.com/bar` will match a config
170+
entry for `https://example.com/bar/baz.git` but will not match a config entry for
171+
`https://example.com/other/repo.git` or `https://example.com/barry/repo.git`
172+
(even though it is a string prefix). To match as a prefix, the pattern
173+
must include protocol and host.
174174
175175
176176
CONFIGURATION OPTIONS

t/t0300-credentials.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -991,18 +991,24 @@ test_expect_success 'url parser not confused by encoded markers' '
991991

992992
test_expect_success 'credential config with partial URLs' '
993993
echo "echo password=yep" | write_script git-credential-yep &&
994-
test_write_lines url=https://[email protected]/repo.git >stdin &&
994+
test_write_lines url=https://[email protected]/org/repo.git >stdin &&
995995
for partial in \
996996
example.com \
997+
example.com/org/repo.git \
997998
999+
[email protected]/org/repo.git \
9981000
https:// \
9991001
https://example.com \
10001002
https://example.com/ \
1003+
https://example.com/org \
1004+
https://example.com/org/ \
1005+
https://example.com/org/repo.git \
10011006
10021007
https://[email protected]/ \
1003-
https://example.com/repo.git \
1004-
https://[email protected]/repo.git \
1005-
/repo.git
1008+
https://[email protected]/org \
1009+
https://[email protected]/org/ \
1010+
https://[email protected]/org/repo.git \
1011+
/org/repo.git
10061012
do
10071013
git -c credential.$partial.helper=yep \
10081014
credential fill <stdin >stdout &&
@@ -1012,7 +1018,12 @@ test_expect_success 'credential config with partial URLs' '
10121018
10131019
for partial in \
10141020
dont.use.this \
1021+
example.com/o \
1022+
10151023
http:// \
1024+
https://example.com/o \
1025+
https://[email protected]/o \
1026+
/o \
10161027
/repo
10171028
do
10181029
git -c credential.$partial.helper=yep \

0 commit comments

Comments
 (0)