submodule: ignore trailing slash in relative url
authorStefan Beller <sbeller@google.com>
Mon, 10 Oct 2016 17:56:11 +0000 (10:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Oct 2016 20:30:31 +0000 (13:30 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/submodule--helper.c
t/t0060-path-utils.sh
index 612e87084c7d00d3534278da975542130faf6e49..569bc8cf3d08d6b189ee9b2b2899fe24d57563b7 100644 (file)
@@ -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))
index 82b98f8cb04a52d7180aa38828beceb528054c44..25b48e5665dafeacb30e324aaadb1720c2e2ce3c 100755 (executable)
@@ -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"