git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v6 2/3] remote: name the original URL when relative_url() fails

From
AGAniket Gupta <aniketgupta3001@gmail.com>
Date
Dec 2, 2026, 20:46 UTC
Message-ID
<20261202204608.97770-3-aniketgupta3001@gmail.com>
In-Reply-To
<20261202204608.97770-1-aniketgupta3001@gmail.com>

When relative_url() cannot resolve a URL, its error message does not name the URL it was given but what is left of it after some "../" components have already been stripped off. With a base URL of "./a/b" and too many "../", it says:

    cannot strip one component off url '.'
which does not help a user to tell what is wrong with the URL.
Name the URL that was passed in instead.
Signed-off-by: Aniket Gupta <aniketgupta3001@gmail.com>
---
 remote.c              | 2 +-
 t/t0060-path-utils.sh | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/remote.c b/remote.c
index 3bca10364e..25e607abf2 100644
--- a/remote.c
+++ b/remote.c
@@ -3183,7 +3183,7 @@ char *relative_url_gently(const char *remote_url, const char *url,
 			if (chopped < 0) {
 				strbuf_addf(err,
 					    _("cannot strip one component off url '%s'"),
-					    remoteurl);
+					    remote_url);
 				free(remoteurl);
 				strbuf_release(&sb);
 				return NULL;
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index 56faf5fe73..0d16b2c884 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -394,6 +394,15 @@ test_submodule_relative_url "../" "$(pwd)/addtest" "../repo" "$(pwd)/repo"
 test_submodule_relative_url "../" "foo/bar" "../submodule" "../foo/submodule"
 test_submodule_relative_url "../" "foo" "../submodule" "../submodule"
 
+test_expect_success 'relative_url() names the URL it was given when it fails' '
+	cat >expect <<-\EOF &&
+	fatal: cannot strip one component off url '\''https://host.example/a'\''
+	EOF
+	test_must_fail test-tool submodule resolve-relative-url "" \
+		"https://host.example/a" ../../../../../../x 2>actual &&
+	test_cmp expect actual
+'
+
 test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c" "../foo/sub/a/b/c"
 test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c/" "../foo/sub/a/b/c"
 test_submodule_relative_url "(null)" "../foo/bar/" "../sub/a/b/c" "../foo/sub/a/b/c"
-- 
2.54.0 (Apple Git-157)
Previous: Aniket GuptaNext: Aniket Gupta
Message 35 of 37 in “bundle-uri: do not die on unresolvable relative URIs”
  1. 0/3 bundle-uri: do not die on unresolvable relative URIsAniket Gupta, Nov 5, 2026
  2. 1/3 remote: add relative_url_gently()Aniket Gupta, Nov 5, 2026
  3. Derrick StoleeNov 6, 2026
  4. 2/3 remote: do not show credentials when relative_url() failsAniket Gupta, Nov 5, 2026
  5. Derrick StoleeNov 6, 2026
  6. Junio C HamanoNov 6, 2026
  7. Aniket GuptaNov 9, 2026
  8. 3/3 bundle-uri: do not die on unresolvable relative URIsAniket Gupta, Nov 5, 2026
  9. Derrick StoleeNov 6, 2026
  10. Derrick StoleeNov 6, 2026
  11. Aniket GuptaNov 6, 2026
  12. Patrick SteinhardtNov 9, 2026
  13. Aniket GuptaNov 9, 2026
  14. 0/3 bundle-uri: do not die on unresolvable relative URIsAniket Gupta, Nov 23, 2026
  15. 1/3 remote: add relative_url_gently()Aniket Gupta, Nov 23, 2026
  16. 2/3 remote: name the original URL when relative_url() failsAniket Gupta, Nov 23, 2026
  17. 3/3 bundle-uri: do not die on unresolvable relative URIsAniket Gupta, Nov 23, 2026
  18. Junio C HamanoNov 23, 2026
  19. Aniket GuptaNov 23, 2026
  20. Derrick StoleeNov 23, 2026
  21. 0/3 bundle-uri: do not die on unresolvable relative URIsAniket Gupta, Nov 26, 2026
  22. 1/3 remote: add relative_url_gently()Aniket Gupta, Nov 26, 2026
  23. 2/3 remote: name the original URL when relative_url() failsAniket Gupta, Nov 26, 2026
  24. Patrick SteinhardtDec 1, 2026
  25. Aniket GuptaDec 1, 2026
  26. 3/3 bundle-uri: do not die on unresolvable relative URIsAniket Gupta, Nov 26, 2026
  27. Derrick StoleeNov 30, 2026
  28. Patrick SteinhardtDec 1, 2026
  29. Aniket GuptaDec 1, 2026
  30. Patrick SteinhardtDec 2, 2026
  31. Patrick SteinhardtDec 1, 2026
  32. Aniket GuptaDec 1, 2026
  33. 0/3 bundle-uri: do not die on unresolvable relative URIsAniket Gupta, Dec 2, 2026
  34. 1/3 remote: add relative_url_gently()Aniket Gupta, Dec 2, 2026
  35. 2/3 remote: name the original URL when relative_url() failsAniket Gupta, Dec 2, 2026
  36. 3/3 bundle-uri: do not die on unresolvable relative URIsAniket Gupta, Dec 2, 2026
  37. Patrick SteinhardtDec 3, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.