Skip to content

Commit 65aaa29

Browse files
committed
Merge branch 'sb/submodule-ignore-trailing-slash'
A minor regression fix for "git submodule". * sb/submodule-ignore-trailing-slash: t0060: sidestep surprising path mangling results on Windows submodule: ignore trailing slash in relative url submodule: ignore trailing slash on superproject URL
2 parents 0d9c527 + 77b63ac commit 65aaa29

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

builtin/submodule--helper.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ static int chop_last_dir(char **remoteurl, int is_relative)
9595
* NEEDSWORK: This works incorrectly on the domain and protocol part.
9696
* remote_url url outcome expectation
9797
* http://a.com/b ../c http://a.com/c as is
98+
* http://a.com/b/ ../c http://a.com/c same as previous line, but
99+
* ignore trailing slash in url
98100
* http://a.com/b ../../c http://c error out
99101
* http://a.com/b ../../../c http:/c error out
100102
* http://a.com/b ../../../../c http:c error out
@@ -113,8 +115,8 @@ static char *relative_url(const char *remote_url,
113115
struct strbuf sb = STRBUF_INIT;
114116
size_t len = strlen(remoteurl);
115117

116-
if (is_dir_sep(remoteurl[len]))
117-
remoteurl[len] = '\0';
118+
if (is_dir_sep(remoteurl[len-1]))
119+
remoteurl[len-1] = '\0';
118120

119121
if (!url_is_local_not_ssh(remoteurl) || is_absolute_path(remoteurl))
120122
is_relative = 0;
@@ -147,6 +149,8 @@ static char *relative_url(const char *remote_url,
147149
}
148150
strbuf_reset(&sb);
149151
strbuf_addf(&sb, "%s%s%s", remoteurl, colonsep ? ":" : "/", url);
152+
if (ends_with(url, "/"))
153+
strbuf_setlen(&sb, sb.len - 1);
150154
free(remoteurl);
151155

152156
if (starts_with_dot_slash(sb.buf))

t/t0060-path-utils.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,36 +305,39 @@ test_git_path GIT_COMMON_DIR=bar config bar/config
305305
test_git_path GIT_COMMON_DIR=bar packed-refs bar/packed-refs
306306
test_git_path GIT_COMMON_DIR=bar shallow bar/shallow
307307

308-
# In the tests below, the distinction between $PWD and $(pwd) is important:
309-
# on Windows, $PWD is POSIX style (/c/foo), $(pwd) has drive letter (c:/foo).
308+
# In the tests below, $(pwd) must be used because it is a native path on
309+
# Windows and avoids MSYS's path mangling (which simplifies "foo/../bar" and
310+
# strips the dot from trailing "/.").
310311

311312
test_submodule_relative_url "../" "../foo" "../submodule" "../../submodule"
312313
test_submodule_relative_url "../" "../foo/bar" "../submodule" "../../foo/submodule"
313314
test_submodule_relative_url "../" "../foo/submodule" "../submodule" "../../foo/submodule"
314315
test_submodule_relative_url "../" "./foo" "../submodule" "../submodule"
315316
test_submodule_relative_url "../" "./foo/bar" "../submodule" "../foo/submodule"
316317
test_submodule_relative_url "../../../" "../foo/bar" "../sub/a/b/c" "../../../../foo/sub/a/b/c"
317-
test_submodule_relative_url "../" "$PWD/addtest" "../repo" "$(pwd)/repo"
318+
test_submodule_relative_url "../" "$(pwd)/addtest" "../repo" "$(pwd)/repo"
318319
test_submodule_relative_url "../" "foo/bar" "../submodule" "../foo/submodule"
319320
test_submodule_relative_url "../" "foo" "../submodule" "../submodule"
320321

321322
test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c" "../foo/sub/a/b/c"
323+
test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c/" "../foo/sub/a/b/c"
324+
test_submodule_relative_url "(null)" "../foo/bar/" "../sub/a/b/c" "../foo/sub/a/b/c"
322325
test_submodule_relative_url "(null)" "../foo/bar" "../submodule" "../foo/submodule"
323326
test_submodule_relative_url "(null)" "../foo/submodule" "../submodule" "../foo/submodule"
324327
test_submodule_relative_url "(null)" "../foo" "../submodule" "../submodule"
325328
test_submodule_relative_url "(null)" "./foo/bar" "../submodule" "foo/submodule"
326329
test_submodule_relative_url "(null)" "./foo" "../submodule" "submodule"
327330
test_submodule_relative_url "(null)" "//somewhere else/repo" "../subrepo" "//somewhere else/subrepo"
328-
test_submodule_relative_url "(null)" "$PWD/subsuper_update_r" "../subsubsuper_update_r" "$(pwd)/subsubsuper_update_r"
329-
test_submodule_relative_url "(null)" "$PWD/super_update_r2" "../subsuper_update_r" "$(pwd)/subsuper_update_r"
330-
test_submodule_relative_url "(null)" "$PWD/." "../." "$(pwd)/."
331-
test_submodule_relative_url "(null)" "$PWD" "./." "$(pwd)/."
332-
test_submodule_relative_url "(null)" "$PWD/addtest" "../repo" "$(pwd)/repo"
333-
test_submodule_relative_url "(null)" "$PWD" "./å äö" "$(pwd)/å äö"
334-
test_submodule_relative_url "(null)" "$PWD/." "../submodule" "$(pwd)/submodule"
335-
test_submodule_relative_url "(null)" "$PWD/submodule" "../submodule" "$(pwd)/submodule"
336-
test_submodule_relative_url "(null)" "$PWD/home2/../remote" "../bundle1" "$(pwd)/home2/../bundle1"
337-
test_submodule_relative_url "(null)" "$PWD/submodule_update_repo" "./." "$(pwd)/submodule_update_repo/."
331+
test_submodule_relative_url "(null)" "$(pwd)/subsuper_update_r" "../subsubsuper_update_r" "$(pwd)/subsubsuper_update_r"
332+
test_submodule_relative_url "(null)" "$(pwd)/super_update_r2" "../subsuper_update_r" "$(pwd)/subsuper_update_r"
333+
test_submodule_relative_url "(null)" "$(pwd)/." "../." "$(pwd)/."
334+
test_submodule_relative_url "(null)" "$(pwd)" "./." "$(pwd)/."
335+
test_submodule_relative_url "(null)" "$(pwd)/addtest" "../repo" "$(pwd)/repo"
336+
test_submodule_relative_url "(null)" "$(pwd)" "./å äö" "$(pwd)/å äö"
337+
test_submodule_relative_url "(null)" "$(pwd)/." "../submodule" "$(pwd)/submodule"
338+
test_submodule_relative_url "(null)" "$(pwd)/submodule" "../submodule" "$(pwd)/submodule"
339+
test_submodule_relative_url "(null)" "$(pwd)/home2/../remote" "../bundle1" "$(pwd)/home2/../bundle1"
340+
test_submodule_relative_url "(null)" "$(pwd)/submodule_update_repo" "./." "$(pwd)/submodule_update_repo/."
338341
test_submodule_relative_url "(null)" "file:///tmp/repo" "../subrepo" "file:///tmp/subrepo"
339342
test_submodule_relative_url "(null)" "foo/bar" "../submodule" "foo/submodule"
340343
test_submodule_relative_url "(null)" "foo" "../submodule" "submodule"

0 commit comments

Comments
 (0)