# [PATCH 0/3] config: support scp-style --url

6 messages from 2026-07-24 to 2026-07-28. Participants: Fabian Pottbäcker, Ben Knoble.
Thread: https://gitlist.dev/t/66055

## Fabian Pottbäcker, 2026-07-24 00:40

Subject: [PATCH 0/3] config: support scp-style --url
Message-ID: <20260724004011.41795-1-fpottbaecker+git@mailbox.org>

```
Almost all git commands support the same set of URL formats, which includes the
scp-style shortcut for ssh. This format is the default format of multiple large
git services, presented to users when pressing a clone button. The config --url
option was a notable exception. This is only relevant for scripting, it only
affects the config get command.

This series consists of three commits: the first adds URL default port
normalization to FTP and SSH, the second adds some git-config tests for --url
which seemed missing (present for --get-urlmatch), and the third uses the
recently added `url_parse` to support scp-style URLs in --url.

Uses in scripting of this change include smaller tools to automatically
configure some settings based on some remote, like setting up author info based
on a user git config value scoped to ssh://service.com, which is useful
because git hosters often offer an email obfuscation/forwarding feature and this
would enable easier management of identities with multiple accounts (like work
and private).

This could of course be more useful with adjustments to `fmt_ident` to support
this, with appropriate config options (what remote, copy values to repo config
or use globals automatically, ...). Which would have been somewhat out of scope
for this and requiring some more intricate changes I did not feel comfortable
with yet.


Fabian Pottbäcker (3):
  urlmatch: normalize ssh and ftp default ports
  t1300: cover --url for some --get-urlmatch tests
  config: use url_parse for --url

 Documentation/git-config.adoc           |  5 +++
 builtin/config.c                        |  2 +-
 t/t1300-config.sh                       | 58 +++++++++++++++++++++++++
 t/unit-tests/u-urlmatch-normalization.c |  9 ++++
 urlmatch.c                              | 16 +++++--
 5 files changed, 85 insertions(+), 5 deletions(-)


base-commit: 9a0c4701dcd5725c4184599322b52933ff5005ca
-- 
2.50.1 (Apple Git-155)


```

## Fabian Pottbäcker, 2026-07-24 00:40

Subject: [PATCH 1/3] urlmatch: normalize ssh and ftp default ports
Message-ID: <20260724004011.41795-2-fpottbaecker+git@mailbox.org>
In-Reply-To: <20260724004011.41795-1-fpottbaecker+git@mailbox.org>

```
These protocols are still supported by git and have well known
default ports. This leaves FTPS, which does not have one default
port.

Signed-off-by: Fabian Pottbäcker <fpottbaecker+git@mailbox.org>
---
 t/unit-tests/u-urlmatch-normalization.c |  9 +++++++++
 urlmatch.c                              | 16 ++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/t/unit-tests/u-urlmatch-normalization.c b/t/unit-tests/u-urlmatch-normalization.c
index 3595d893a2..1808e5e51f 100644
--- a/t/unit-tests/u-urlmatch-normalization.c
+++ b/t/unit-tests/u-urlmatch-normalization.c
@@ -141,9 +141,18 @@ void test_urlmatch_normalization__port_normalization(void)
 	check_normalized_url("http://x:80", "http://x/");
 	check_normalized_url("http://x:080", "http://x/");
 	check_normalized_url("http://x:000000080", "http://x/");
+	check_normalized_url("https://x:8443", "https://x:8443/");
 	check_normalized_url("https://x:443", "https://x/");
 	check_normalized_url("https://x:0443", "https://x/");
 	check_normalized_url("https://x:000000443", "https://x/");
+	check_normalized_url("ftp://x:2121", "ftp://x:2121/");
+	check_normalized_url("ftp://x:21", "ftp://x/");
+	check_normalized_url("ftp://x:021", "ftp://x/");
+	check_normalized_url("ftp://x:00000021", "ftp://x/");
+	check_normalized_url("ssh://x:2222", "ssh://x:2222/");
+	check_normalized_url("ssh://x:22", "ssh://x/");
+	check_normalized_url("ssh://x:022", "ssh://x/");
+	check_normalized_url("ssh://x:00000022", "ssh://x/");
 }
 
 void test_urlmatch_normalization__general_escape(void)
diff --git a/urlmatch.c b/urlmatch.c
index 20bc2d009c..0c2ddf2e40 100644
--- a/urlmatch.c
+++ b/urlmatch.c
@@ -274,12 +274,20 @@ static char *url_normalize_1(const char *url, struct url_info *out_info, bool al
 		if (url == slash_ptr) {
 			/* Skip ":" port with no number, it's same as default */
 		} else if (slash_ptr - url == 2 &&
-			   starts_with(norm.buf, "http:") &&
-			   !strncmp(url, "80", 2)) {
+			    starts_with(norm.buf, "ftp:") &&
+			    !strncmp(url, "21", 2)) {
+			/* Skip http :21 as it's the default */
+		} else if (slash_ptr - url == 2 &&
+			    starts_with(norm.buf, "ssh:") &&
+			    !strncmp(url, "22", 2)) {
+			/* Skip http :22 as it's the default */
+		} else if (slash_ptr - url == 2 &&
+			    starts_with(norm.buf, "http:") &&
+			    !strncmp(url, "80", 2)) {
 			/* Skip http :80 as it's the default */
 		} else if (slash_ptr - url == 3 &&
-			   starts_with(norm.buf, "https:") &&
-			   !strncmp(url, "443", 3)) {
+			    starts_with(norm.buf, "https:") &&
+			    !strncmp(url, "443", 3)) {
 			/* Skip https :443 as it's the default */
 		} else {
 			/*
-- 
2.50.1 (Apple Git-155)


```

## Fabian Pottbäcker, 2026-07-24 00:40

Subject: [PATCH 2/3] t1300: cover --url for some --get-urlmatch tests
Message-ID: <20260724004011.41795-3-fpottbaecker+git@mailbox.org>
In-Reply-To: <20260724004011.41795-1-fpottbaecker+git@mailbox.org>

```
Signed-off-by: Fabian Pottbäcker <fpottbaecker+git@mailbox.org>
---
 t/t1300-config.sh | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/t/t1300-config.sh b/t/t1300-config.sh
index b99f782d5d..8310fe6a65 100755
--- a/t/t1300-config.sh
+++ b/t/t1300-config.sh
@@ -2028,22 +2028,32 @@ test_expect_success 'urlmatch with wildcard' '
 
 	test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual &&
 	test_must_be_empty actual &&
+	test_expect_code 1 git config get --bool --url=https://good.example.com doesnt.exist >actual &&
+	test_must_be_empty actual &&
 
 	echo true >expect &&
 	git config --bool --get-urlmatch http.SSLverify https://example.com >actual &&
 	test_cmp expect actual &&
+	git config get --bool --url=https://example.com http.SSLverify >actual &&
+	test_cmp expect actual &&
 
 	echo true >expect &&
 	git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual &&
 	test_cmp expect actual &&
+	git config get --bool --url=https://good-example.com http.SSLverify >actual &&
+	test_cmp expect actual &&
 
 	echo true >expect &&
 	git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual &&
 	test_cmp expect actual &&
+	git config get --bool --url=https://deep.nested.example.com http.sslverify >actual &&
+	test_cmp expect actual &&
 
 	echo false >expect &&
 	git config --bool --get-urlmatch http.sslverify https://good.example.com >actual &&
 	test_cmp expect actual &&
+	git config get --bool --url=https://good.example.com http.sslverify >actual &&
+	test_cmp expect actual &&
 
 	{
 		echo http.cookiefile /tmp/cookie.txt &&
@@ -2051,9 +2061,13 @@ test_expect_success 'urlmatch with wildcard' '
 	} >expect &&
 	git config --get-urlmatch HTTP https://good.example.com >actual &&
 	test_cmp expect actual &&
+	git config get --url=https://good.example.com HTTP >actual &&
+	test_cmp expect actual &&
 
 	echo http.sslverify >expect &&
 	git config --get-urlmatch HTTP https://more.example.com.au >actual &&
+	test_cmp expect actual &&
+	git config get --url=https://more.example.com.au HTTP >actual &&
 	test_cmp expect actual
 '
 
-- 
2.50.1 (Apple Git-155)


```

## Fabian Pottbäcker, 2026-07-24 00:40

Subject: [PATCH 3/3] config: use url_parse for --url
Message-ID: <20260724004011.41795-4-fpottbaecker+git@mailbox.org>
In-Reply-To: <20260724004011.41795-1-fpottbaecker+git@mailbox.org>

```
This enables the use of the scp-style URL syntax for this option and
the depracated --get-urlmatch. Since URL matching was primarily used
for http(s) transports previously (with the potential exception of
promisor.acceptFromServerUrl), this has little internal effect and
mostly brings the behaviour of this URL argument in line with other
commands.

Signed-off-by: Fabian Pottbäcker <fpottbaecker+git@mailbox.org>
---
 Documentation/git-config.adoc |  5 ++++
 builtin/config.c              |  2 +-
 t/t1300-config.sh             | 44 +++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-config.adoc b/Documentation/git-config.adoc
index 57af010ade..a38d68512e 100644
--- a/Documentation/git-config.adoc
+++ b/Documentation/git-config.adoc
@@ -143,6 +143,11 @@ permitted).
 	<section>.<key> is used as a fallback).  When given just the
 	<section> as name, do so for all the keys in the section and
 	list them.  Returns error code 1 if no value is found.
++
+This option supports all URL formats (see linkgit:git-fetch[1]),
+unlike the config file URL syntax explained in the `http.<url>.*`
+options, which requires an explicitly specified scheme and does
+not support the scp-style URL syntax.
 
 --global::
 	For writing options: write to global `~/.gitconfig` file
diff --git a/builtin/config.c b/builtin/config.c
index 8d8ec0beea..b5488a9497 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -870,7 +870,7 @@ static int get_urlmatch(const struct config_location_options *opts,
 	config.cascade_fn = NULL;
 	config.cb = &values;
 
-	if (!url_normalize(url, &config.url))
+	if (!url_parse(url, &config.url))
 		die("%s", config.url.err);
 
 	config.section = section = xstrdup_tolower(var);
diff --git a/t/t1300-config.sh b/t/t1300-config.sh
index 8310fe6a65..477e030cf3 100755
--- a/t/t1300-config.sh
+++ b/t/t1300-config.sh
@@ -1907,6 +1907,50 @@ test_expect_success 'urlmatch' '
 	test_cmp expect actual
 '
 
+test_expect_success 'urlmatch with scp syntax' '
+	cat >.git/config <<-\EOF &&
+	[section]
+		flag = false
+	[section "ssh://example.com"]
+		flag = true
+		key = value
+	EOF
+
+	echo "fatal: invalid URL scheme name or missing '"'"'://'"'"' suffix" >expect_err &&
+	test_expect_code 128 git config --bool --get-urlmatch section.flag example.com >actual 2>error &&
+	test_cmp expect_err error &&
+	test_must_be_empty actual &&
+	test_expect_code 128 git config get --url=example.com --bool section.flag >actual 2>error &&
+	test_cmp expect_err error &&
+	test_must_be_empty actual &&
+
+	test_expect_code 1 git config --bool --get-urlmatch doesnt.exist example.com: >actual &&
+	test_must_be_empty actual &&
+	test_expect_code 1 git config get --url=example.com: --bool doesnt.exist >actual &&
+	test_must_be_empty actual &&
+
+	echo true >expect &&
+	git config --bool --get-urlmatch section.flag git@example.com:path >actual &&
+	test_cmp expect actual &&
+	git config get --bool --url=git@example.com:path section.flag >actual &&
+	test_cmp expect actual &&
+
+	echo false >expect &&
+	git config --bool --get-urlmatch section.flag https://example.com >actual &&
+	test_cmp expect actual &&
+	git config get --bool --url=https://example.com section.flag >actual &&
+	test_cmp expect actual &&
+
+	{
+		echo section.flag true &&
+		echo section.key value
+	} >expect &&
+	git config --get-urlmatch section git@example.com:path >actual &&
+	test_cmp expect actual &&
+	git config get --url=git@example.com:path section >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'urlmatch with --show-scope' '
 	cat >.git/config <<-\EOF &&
 	[http "https://weak.example.com"]
-- 
2.50.1 (Apple Git-155)


```

## Ben Knoble, 2026-07-24 11:35

Subject: Re: [PATCH 1/3] urlmatch: normalize ssh and ftp default ports
Message-ID: <DE62DFBE-ED4C-4EF5-8F4D-FAAB3519F86A@gmail.com>
In-Reply-To: <20260724004011.41795-2-fpottbaecker+git@mailbox.org>

```

> Le 24 juil. 2026 à 09:41, Fabian Pottbäcker <fpottbaecker+git@mailbox.org> a écrit :
> 
> ﻿These protocols are still supported by git and have well known
> default ports. This leaves FTPS, which does not have one default
> port.
> 
> Signed-off-by: Fabian Pottbäcker <fpottbaecker+git@mailbox.org>
> ---
> t/unit-tests/u-urlmatch-normalization.c |  9 +++++++++
> urlmatch.c                              | 16 ++++++++++++----
> 2 files changed, 21 insertions(+), 4 deletions(-)
> 

[snip]

> diff --git a/urlmatch.c b/urlmatch.c
> index 20bc2d009c..0c2ddf2e40 100644
> --- a/urlmatch.c
> +++ b/urlmatch.c
> @@ -274,12 +274,20 @@ static char *url_normalize_1(const char *url, struct url_info *out_info, bool al
>        if (url == slash_ptr) {
>            /* Skip ":" port with no number, it's same as default */
>        } else if (slash_ptr - url == 2 &&
> -               starts_with(norm.buf, "http:") &&
> -               !strncmp(url, "80", 2)) {
> +                starts_with(norm.buf, "ftp:") &&
> +                !strncmp(url, "21", 2)) {
> +            /* Skip http :21 as it's the default */
> +        } else if (slash_ptr - url == 2 &&
> +                starts_with(norm.buf, "ssh:") &&
> +                !strncmp(url, "22", 2)) {
> +            /* Skip http :22 as it's the default */
> +        } else if (slash_ptr - url == 2 &&
> +                starts_with(norm.buf, "http:") &&
> +                !strncmp(url, "80", 2)) {
>            /* Skip http :80 as it's the default */
>        } else if (slash_ptr - url == 3 &&
> -               starts_with(norm.buf, "https:") &&
> -               !strncmp(url, "443", 3)) {
> +                starts_with(norm.buf, "https:") &&
> +                !strncmp(url, "443", 3)) {
>            /* Skip https :443 as it's the default */
>        } else {
>            /*
> --
> 2.50.1 (Apple Git-155)

Just offhand, not commenting on the rest of the series : the comments look wrong for ftp, ssh to me. 
```

## Fabian Pottbäcker, 2026-07-28 10:51

Subject: Re: [PATCH 1/3] urlmatch: normalize ssh and ftp default ports
Message-ID: <32323233-CE82-421A-94D2-5902C4382F8D@mailbox.org>
In-Reply-To: <DE62DFBE-ED4C-4EF5-8F4D-FAAB3519F86A@gmail.com>

```
> On 24. Jul 2026, at 13:35, Ben Knoble <ben.knoble@gmail.com> wrote:
> 
> Just offhand, not commenting on the rest of the series : the comments look wrong for ftp, ssh to me.

Right, I messed up the continuation indent here (I wanted to make it in line with the rest of the file).
Lined up for a v2, but it is minor so I would await further comments for now (see https://gitlab.com/fpottbaecker/git/-/compare/config_url_scp_syntax_v1..config_url_scp_syntax).

Also, since I noticed this as a convenience thing gitgitgadget does:

Fetch-It-Via: git fetch https://gitlab.com/fpottbaecker/git.git config_url_scp_syntax_v1
```
