submodule: ignore trailing slash on superproject URL
Before 63e95beb0 (2016-04-15, submodule: port resolve_relative_url from shell to C), it did not matter if the superprojects URL had a trailing slash or not. It was just chopped off as one of the first steps (The "remoteurl=${remoteurl%/}" near the beginning of resolve_relative_url(), which was removed in said commit). When porting this to the C version, an off-by-one error was introduced and we did not check the actual last character to be a slash, but the NULL delimiter. Reintroduce the behavior from before 63e95beb0, to ignore the trailing slash. Reported-by: <venv21@gmail.com> Helped-by: Dennis Kaarsemaker <dennis@kaarsemaker.net> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Oct 10, 2016 at 10:56 UTC
087885049e38c38a437153055ff521567132b183
2 files changed
+5
-2
builtin/submodule--helper.c
+4
-2
@@ -95,6 +95,8 @@ static int chop_last_dir(char **remoteurl, int is_relative)
95
* NEEDSWORK: This works incorrectly on the domain and protocol part.
96
* remote_url url outcome expectation
97
* 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
100
* http://a.com/b ../../c http://c error out
101
* http://a.com/b ../../../c http:/c error out
102
* http://a.com/b ../../../../c http:c error out
@@ -113,8 +115,8 @@ static char *relative_url(const char *remote_url,
115
struct strbuf sb = STRBUF_INIT;
116
size_t len = strlen(remoteurl);
117
116
- if (is_dir_sep(remoteurl[len]))
117
- remoteurl[len] = '\0';
118
+ if (is_dir_sep(remoteurl[len-1]))
119
+ remoteurl[len-1] = '\0';
120
121
if (!url_is_local_not_ssh(remoteurl) || is_absolute_path(remoteurl))
122
is_relative = 0;
t/t0060-path-utils.sh
+1
@@ -319,6 +319,7 @@ test_submodule_relative_url "../" "foo/bar" "../submodule" "../foo/submodule"
319
test_submodule_relative_url "../" "foo" "../submodule" "../submodule"
320
321
test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c" "../foo/sub/a/b/c"
322
+test_submodule_relative_url "(null)" "../foo/bar/" "../sub/a/b/c" "../foo/sub/a/b/c"
323
test_submodule_relative_url "(null)" "../foo/bar" "../submodule" "../foo/submodule"
324
test_submodule_relative_url "(null)" "../foo/submodule" "../submodule" "../foo/submodule"
325
test_submodule_relative_url "(null)" "../foo" "../submodule" "../submodule"