git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "M Hickford via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: sandals@crustytoothpaste.net, Johannes.Schindelin@gmx.de,
	M Hickford <mirth.hickford@gmail.com>,
	M Hickford <mirth.hickford@gmail.com>
Subject: [PATCH v2] docs/gitcredentials: describe URL prefix matching
Date: Fri, 03 Oct 2025 20:58:53 +0000	[thread overview]
Message-ID: <pull.1979.v2.git.1759525133638.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1979.git.1759352209657.gitgitgadget@gmail.com>

From: M Hickford <mirth.hickford@gmail.com>

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>
---
    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(-)

diff --git a/Documentation/gitcredentials.adoc b/Documentation/gitcredentials.adoc
index 3337bb475d..bf595f7918 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,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
diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh
index cb3a85c7ff..07aa834d33 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 <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 \

base-commit: 821f583da6d30a84249f75f33501504d597bc16b
-- 
gitgitgadget

  parent reply	other threads:[~2025-10-03 20:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-01 20:56 [PATCH] docs/gitcredentials: describe URL prefix matching M Hickford via GitGitGadget
2025-10-01 22:20 ` brian m. carlson
2025-10-03 20:58 ` M Hickford via GitGitGadget [this message]
2025-10-03 21:24   ` [PATCH v2] " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1979.v2.git.1759525133638.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=mirth.hickford@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).