Skip to contentSkip to conversation

docs/gitcredentials: describe URL prefix matching

PATCH Superseded M Hickford via GitGitGadget 3 participants 4 messages Oct 1, 2025 – Oct 3, 2025 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 docs/gitcredentials: describe URL prefix matching

From: M Hickford <[email protected]>

Documentation was inaccurate since 9a121b0d226 (credential: handle credential.<partial-URL>.<key> again, 2020-04-24)

Add tests for documented behaviour.

---
docs/gitcredentials: describe URL prefix matching

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1979%2Fhickford%2Furl-prefix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1979/hickford/url-prefix-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1979

 Documentation/gitcredentials.adoc | 15 +++++++--------
 t/t0300-credentials.sh            | 19 +++++++++++++++----
 2 files changed, 22 insertions(+), 12 deletions(-)
Documentation/gitcredentials.adoc +7 -8
index 3337bb475d..60c2cc4ade 100644
@@ -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.<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
t/t0300-credentials.sh +15 -4
index cb3a85c7ff..07aa834d33 100755
@@ -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://[email protected]/repo.git >stdin &&
+	test_write_lines url=https://[email protected]/org/repo.git >stdin &&
 	for partial in \
 		example.com \
+		example.com/org/repo.git \
 		[email protected] \
+		[email protected]/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://[email protected] \
 		https://[email protected]/ \
-		https://example.com/repo.git \
-		https://[email protected]/repo.git \
-		/repo.git
+		https://[email protected]/org \
+		https://[email protected]/org/ \
+		https://[email protected]/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 \
+		[email protected]/o \
 		http:// \
+		https://example.com/o \
+		https://[email protected]/o \
+		/o \
 		/repo
 	do
 		git -c credential.$partial.helper=yep \

base-commit: 821f583da6d30a84249f75f33501504d597bc16b

Signature · 1 line
gitgitgadget
#1 lore raw
Quoted 20 lines · M Hickford via GitGitGadget
Documentation/gitcredentials.adoc +2 -3
index 3337bb475d..60c2cc4ade 100644
@@ -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.<URL>.*`
 options.
 

Documentation/gitcredentials.adoc match: Git compares the protocols exactly. However, you may use wildcards in · line 172

Quoted 10 lines
Documentation/gitcredentials.adoc +5 -5
-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).

This looks like a good description.

Quoted 37 lines
Documentation/gitcredentials.adoc +0 -0
 CONFIGURATION OPTIONS
t/t0300-credentials.sh +10 -4
index cb3a85c7ff..07aa834d33 100755
@@ -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://[email protected]/repo.git >stdin &&
+	test_write_lines url=https://[email protected]/org/repo.git >stdin &&
 	for partial in \
 		example.com \
+		example.com/org/repo.git \
 		[email protected] \
+		[email protected]/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://[email protected] \
 		https://[email protected]/ \
-		https://example.com/repo.git \
-		https://[email protected]/repo.git \
-		/repo.git
+		https://[email protected]/org \
+		https://[email protected]/org/ \
+		https://[email protected]/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 \

t/t0300-credentials.sh test_expect_success 'credential config with partial URLs' ' · line 1029

Quoted 10 lines
t/t0300-credentials.sh +5 -0
 		dont.use.this \
+		example.com/o \
+		[email protected]/o \
 		http:// \
+		https://example.com/o \
+		https://[email protected]/o \
+		/o \
 		/repo
 	do
 		git -c credential.$partial.helper=yep \

I appreciate the additional tests here.

Signature · 2 lines
brian m. carlson (they/them)
Toronto, Ontario, CA
#2 lore raw

PATCH v2 1/1 docs/gitcredentials: describe URL prefix matching

In reply to M Hickford via GitGitGadget

From: M Hickford <[email protected]>

Documentation was inaccurate since 9a121b0d226 (credential: handle credential.<partial-URL>.<key> again, 2020-04-24)

Add tests for documented behaviour.

---
docs/gitcredentials: describe URL prefix matching

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1979%2Fhickford%2Furl-prefix-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1979/hickford/url-prefix-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1979

Range-diff vs v1:

1: 15f44a2ac5 ! 1: 4b64cf47e9 docs/gitcredentials: describe URL prefix matching
@@ Documentation/gitcredentials.adoc: match: Git compares the protocols exactly. H
-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 ++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

 Documentation/gitcredentials.adoc | 16 ++++++++--------
 t/t0300-credentials.sh            | 19 +++++++++++++++----
 2 files changed, 23 insertions(+), 12 deletions(-)
Documentation/gitcredentials.adoc +8 -8
index 3337bb475d..bf595f7918 100644
@@ -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,12 @@ 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 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). To match as a prefix, the pattern
+must include protocol and host.
 
 
 CONFIGURATION OPTIONS
t/t0300-credentials.sh +15 -4
index cb3a85c7ff..07aa834d33 100755
@@ -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://[email protected]/repo.git >stdin &&
+	test_write_lines url=https://[email protected]/org/repo.git >stdin &&
 	for partial in \
 		example.com \
+		example.com/org/repo.git \
 		[email protected] \
+		[email protected]/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://[email protected] \
 		https://[email protected]/ \
-		https://example.com/repo.git \
-		https://[email protected]/repo.git \
-		/repo.git
+		https://[email protected]/org \
+		https://[email protected]/org/ \
+		https://[email protected]/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 \
+		[email protected]/o \
 		http:// \
+		https://example.com/o \
+		https://[email protected]/o \
+		/o \
 		/repo
 	do
 		git -c credential.$partial.helper=yep \

base-commit: 821f583da6d30a84249f75f33501504d597bc16b

Signature · 1 line
gitgitgadget
#3 lore raw
Quoted 10 lines · M Hickford via GitGitGadget

From: M Hickford <[email protected]>

Documentation was inaccurate since 9a121b0d226 (credential: handle credential.<partial-URL>.<key> again, 2020-04-24)

Add tests for documented behaviour.

---
docs/gitcredentials: describe URL prefix matching

Hmph, v1 was merged to 'next' already yesterday, so a replacement patch is not what I was expecting to see. Can you make an incremental update instead?

Thanks.