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

[PATCH 2/2] submodule: ignore trailing slash in relative url

From
Stefan Beller <sbeller@google.com>
Date
Oct 10, 2016, 17:56 UTC
Message-ID
<20161010175611.1058-2-sbeller@google.com>
In-Reply-To
<20161010175611.1058-1-sbeller@google.com>

This is similar to the previous patch, though no user reported a bug and I could not find a regressive behavior.

However it is a good thing to be strict on the output and for that we always omit a trailing slash.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c | 2 ++
 t/t0060-path-utils.sh       | 1 +
 2 files changed, 3 insertions(+)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a7841a5..260f46f 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -149,6 +149,8 @@ static char *relative_url(const char *remote_url,
 	}
 	strbuf_reset(&sb);
 	strbuf_addf(&sb, "%s%s%s", remoteurl, colonsep ? ":" : "/", url);
+	if (ends_with(url, "/"))
+		strbuf_setlen(&sb, sb.len - 1);
 	free(remoteurl);
 
 	if (starts_with_dot_slash(sb.buf))
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index 82b98f8..25b48e5 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -319,6 +319,7 @@ test_submodule_relative_url "../" "foo/bar" "../submodule" "../foo/submodule"
 test_submodule_relative_url "../" "foo" "../submodule" "../submodule"
 
 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"
 test_submodule_relative_url "(null)" "../foo/bar" "../submodule" "../foo/submodule"
 test_submodule_relative_url "(null)" "../foo/submodule" "../submodule" "../foo/submodule"
-- 
2.10.1.382.ga23ca1b.dirty
Previous: Stefan BellerNext: Dennis Kaarsemaker
Message 2 of 14 in “submodule: ignore trailing slash on superproject URL”
  1. 1/2 submodule: ignore trailing slash on superproject URLStefan Beller, Oct 10, 2016
  2. 2/2 submodule: ignore trailing slash in relative urlStefan Beller, Oct 10, 2016
  3. Dennis KaarsemakerOct 10, 2016
  4. Johannes SchindelinOct 12, 2016
  5. Stefan BellerOct 12, 2016
  6. Johannes SchindelinOct 13, 2016
  7. Junio C HamanoOct 17, 2016
  8. Stefan BellerOct 17, 2016
  9. Junio C HamanoOct 17, 2016
  10. Stefan BellerOct 17, 2016
  11. Junio C HamanoOct 17, 2016
  12. Johannes SixtOct 17, 2016
  13. Junio C HamanoOct 17, 2016
  14. Johannes SixtOct 18, 2016

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.