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

[PATCH] submodule: add more exhaustive up-path testing

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Aug 14, 2018, 18:59 UTC
Message-ID
<20180814185906.2680-1-avarab@gmail.com>

The tests added in 63e95beb08 ("submodule: port resolve_relative_url from shell to C", 2016-04-15) didn't do a good job of testing various up-path invocations where the up-path would bring us beyond even the URL in question without emitting an error.

These results look nonsensical, but it's worth exhaustively testing them before fixing any of this code, so we can see which of these cases were changed.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

The reason I started to poke at this was because I wanted to add support for relative URLs like //group/project.

This solves the problem of there being e.g. a myhost.com/group/project which includes a ../submodule submodule pointing to myhost.com/group/submodule , and me wanting to fork it to myhost.com/myuser/project.

But of course with ../submodule the relative URL will point to myhost.com/myuser/submodule, which won't exist.

So I was hoping to find some point in the relative URL code where we were actually aware of what the host boundary was, so I could just cut off everything after that if //group/project was provided, strip off one slash to make it /group/project, and call it a day.

But as the tests below show the code isn't aware of that at all, and will happily trample over the host(name) to produce nonsensical results.

So I think these tests are worthwihle in themselves, but would like some advice on how to proceed with that from someone more familiar with submodules.

 t/t0060-path-utils.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index 21a8b53132..cd74c0a471 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -330,6 +330,9 @@ test_submodule_relative_url "(null)" "../foo" "../submodule" "../submodule"
 test_submodule_relative_url "(null)" "./foo/bar" "../submodule" "foo/submodule"
 test_submodule_relative_url "(null)" "./foo" "../submodule" "submodule"
 test_submodule_relative_url "(null)" "//somewhere else/repo" "../subrepo" "//somewhere else/subrepo"
+test_submodule_relative_url "(null)" "//somewhere else/repo" "../../subrepo" "//subrepo"
+test_submodule_relative_url "(null)" "//somewhere else/repo" "../../../subrepo" "/subrepo"
+test_submodule_relative_url "(null)" "//somewhere else/repo" "../../../../subrepo" "subrepo"
 test_submodule_relative_url "(null)" "$(pwd)/subsuper_update_r" "../subsubsuper_update_r" "$(pwd)/subsubsuper_update_r"
 test_submodule_relative_url "(null)" "$(pwd)/super_update_r2" "../subsuper_update_r" "$(pwd)/subsuper_update_r"
 test_submodule_relative_url "(null)" "$(pwd)/." "../." "$(pwd)/."
@@ -344,10 +347,20 @@ test_submodule_relative_url "(null)" "file:///tmp/repo" "../subrepo" "file:///tm
 test_submodule_relative_url "(null)" "foo/bar" "../submodule" "foo/submodule"
 test_submodule_relative_url "(null)" "foo" "../submodule" "submodule"
 test_submodule_relative_url "(null)" "helper:://hostname/repo" "../subrepo" "helper:://hostname/subrepo"
+test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../subrepo" "helper:://subrepo"
+test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../subrepo" "helper::/subrepo"
+test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../subrepo" "helper::subrepo"
+test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../../subrepo" "helper:subrepo"
+test_submodule_relative_url "(null)" "helper:://hostname/repo" "../../../../../../subrepo" ".:subrepo"
 test_submodule_relative_url "(null)" "ssh://hostname/repo" "../subrepo" "ssh://hostname/subrepo"
+test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../subrepo" "ssh://subrepo"
+test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../subrepo" "ssh:/subrepo"
+test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../../subrepo" "ssh:subrepo"
+test_submodule_relative_url "(null)" "ssh://hostname/repo" "../../../../../subrepo" ".:subrepo"
 test_submodule_relative_url "(null)" "ssh://hostname:22/repo" "../subrepo" "ssh://hostname:22/subrepo"
 test_submodule_relative_url "(null)" "user@host:path/to/repo" "../subrepo" "user@host:path/to/subrepo"
 test_submodule_relative_url "(null)" "user@host:repo" "../subrepo" "user@host:subrepo"
+test_submodule_relative_url "(null)" "user@host:repo" "../../subrepo" ".:subrepo"
 
 test_expect_success 'match .gitmodules' '
 	test-tool path-utils is_dotgitmodules \
-- 
2.18.0.865.gffc8e1a3cd6
Next: Stefan Beller
Message 1 of 7 in “submodule: add more exhaustive up-path testing”
  1. submodule: add more exhaustive up-path testingÆvar Arnfjörð Bjarmason, Aug 14, 2018
  2. Stefan BellerAug 14, 2018
  3. Junio C HamanoAug 14, 2018
  4. Ævar Arnfjörð BjarmasonAug 14, 2018
  5. Stefan BellerAug 14, 2018
  6. Ævar Arnfjörð BjarmasonAug 14, 2018
  7. Stefan BellerAug 14, 2018

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.