]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t5801: test remote.*.vcs config
authorJeff King <peff@peff.net>
Fri, 14 Jun 2024 10:34:54 +0000 (06:34 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 14 Jun 2024 16:34:38 +0000 (09:34 -0700)
The usual way to trigger a remote helper is to use the "::" syntax from:
87422439d1 (Allow specifying the remote helper in the url, 2009-11-18).
Doing:

  git config remote.origin.url hg::https://example.com/repo

will run "git-remote-hg origin https://example.com/repo". Or you can
use the fallback handling from 25d5cc488a (Pass unknown protocols to
external protocol handlers, 2009-12-09):

  git config remote.origin.url "foo://bar"

which will run "git-remote-foo origin foo://bar".

But there's a third way, from c578f51d52 (Add a config option for
remotes to specify a foreign vcs, 2009-11-18):

  git config remote.origin.vcs foo
  git config remote.origin.url bar

which will run "git-remote-foo origin bar". This is mostly redundant
with the other methods, except that it is supposed to allow you to run
without a URL at all. So:

  git config remote.origin.vcs foo

would run "git-remote-foo origin" with no extra URL parameter (under the
assumption that the helper somehow knows how to access the remote repo).
However, this mode has been broken since 25d5cc488a, shortly after it
was added! That commit taught the transport code to always look at the
URL string to parse off the "foo::" bits, meaning it would always
segfault in the no-url case. You can see that with:

  git -c remote.foo.vcs=bar fetch foo

Nobody seems to have noticed in the almost 15 years since, so presumably
it's not a well-used feature. And without that, arguably the whole
remote.*.vcs feature could be removed entirely, as it isn't offering
anything you couldn't do with the "helper::" syntax. But it _does_ work
if you have a URL, and it has been advertised in the documentation for
all that time. So we shouldn't just remove it without warning.

Likewise, even if we were going to deprecate it, we should avoid
breaking it in the meantime. Since there are no tests for it at all,
let's add a few basic ones:

  - this syntax doesn't work well with "git clone" (another point
    against it versus "helper::"). But we can use "clone -c" to set up
    the config manually, passing the URL as usual to clone. This does
    work, though note that I had to use --no-local in the test to avoid
    broken interactions between the local code and the helper. In the
    real world this would be a non-issue, since the remote URL would
    generally not also be a local Git repo!

  - likewise, we should be able to set up the config manually and fetch
    into a repository. This also works.

  - we can simulate a vcs that has no URL support by stuffing the remote
    path into another environment variable. This should work, but
    doesn't (it hits the segfault mentioned above).

In the first two cases, I took the extra step of checking GIT_TRACE
output to confirm that we actually ran the helper (since the URL is a
valid Git repo, the clone/fetch would appear to work even if we
didn't use the helper at all!).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5801-remote-helpers.sh
t/t5801/git-remote-nourl [new file with mode: 0755]

index 4e0a77f9859b392b06edd9f3696e804271d6f225..7c8c4359aa98c995f19dbf30088ad3713a50f42d 100755 (executable)
@@ -38,6 +38,29 @@ test_expect_success 'cloning from local repo' '
        test_cmp server/file local/file
 '
 
+test_expect_success 'clone with remote.*.vcs config' '
+       GIT_TRACE=$PWD/vcs-clone.trace \
+       git clone --no-local -c remote.origin.vcs=testgit "$PWD/server" vcs-clone &&
+       test_grep remote-testgit vcs-clone.trace
+'
+
+test_expect_success 'fetch with configured remote.*.vcs' '
+       git init vcs-fetch &&
+       git -C vcs-fetch config remote.origin.vcs testgit &&
+       git -C vcs-fetch config remote.origin.url "$PWD/server" &&
+       GIT_TRACE=$PWD/vcs-fetch.trace \
+       git -C vcs-fetch fetch origin &&
+       test_grep remote-testgit vcs-fetch.trace
+'
+
+test_expect_failure 'vcs remote with no url' '
+       NOURL_UPSTREAM=$PWD/server &&
+       export NOURL_UPSTREAM &&
+       git init vcs-nourl &&
+       git -C vcs-nourl config remote.origin.vcs nourl &&
+       git -C vcs-nourl fetch origin
+'
+
 test_expect_success 'create new commit on remote' '
        (cd server &&
         echo content >>file &&
diff --git a/t/t5801/git-remote-nourl b/t/t5801/git-remote-nourl
new file mode 100755 (executable)
index 0000000..09be601
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec git-remote-testgit "$1" "$NOURL_UPSTREAM"