Skip to content

Commit 94bc83c

Browse files
peffgitster
authored andcommitted
git_connect: let user override virtual-host we send to daemon
When we connect to a git-daemon at a given host and port, we actually send the string "localhost:9418" to the other side, which allows it to do virtual-hosting lookups. For testing and debugging, we'd like to be able to send arbitrary strings, rather than the hostname we actually connected to. Using "insteadOf" config does not work for this purpose, as the hostname determination happens at a very low level, right before we feed the hostname to our lookup routines. You could use /etc/hosts or similar to get around this, but we cannot do that portably from our test suite. Instead, this patch provides an environment variable that can be used to send an arbitrary string. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c84ac8 commit 94bc83c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

connect.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,20 @@ struct child_process *git_connect(int fd[2], const char *url,
673673
printf("Diag: path=%s\n", path ? path : "NULL");
674674
conn = NULL;
675675
} else if (protocol == PROTO_GIT) {
676+
/*
677+
* Set up virtual host information based on where we will
678+
* connect, unless the user has overridden us in
679+
* the environment.
680+
*/
681+
char *target_host = getenv("GIT_OVERRIDE_VIRTUAL_HOST");
682+
if (target_host)
683+
target_host = xstrdup(target_host);
684+
else
685+
target_host = xstrdup(hostandport);
686+
676687
/* These underlying connection commands die() if they
677688
* cannot connect.
678689
*/
679-
char *target_host = xstrdup(hostandport);
680690
if (git_use_proxy(hostandport))
681691
conn = git_proxy_connect(fd, hostandport);
682692
else

0 commit comments

Comments
 (0)