Skip to content

Commit 3f55cca

Browse files
tboegigitster
authored andcommitted
t5500: show user name and host in diag-url
The URL for ssh may have include a username before the hostname, like ssh://user@host/repo. When literal IPV6 addresses are used together with a username, the substring "user@[::1]" must be converted into "user@::1". Make that conversion visible for the user, and write userandhost in the diagnostics Signed-off-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9f69765 commit 3f55cca

File tree

2 files changed

+56
-30
lines changed

2 files changed

+56
-30
lines changed

connect.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ struct child_process *git_connect(int fd[2], const char *url,
675675
signal(SIGCHLD, SIG_DFL);
676676

677677
protocol = parse_connect_url(url, &hostandport, &path);
678-
if (flags & CONNECT_DIAG_URL) {
678+
if ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {
679679
printf("Diag: url=%s\n", url ? url : "NULL");
680680
printf("Diag: protocol=%s\n", prot_name(protocol));
681681
printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
@@ -719,18 +719,29 @@ struct child_process *git_connect(int fd[2], const char *url,
719719
get_host_and_port(&ssh_host, &port);
720720
if (!port)
721721
port = get_port(ssh_host);
722-
723-
if (!ssh) ssh = "ssh";
724-
725-
argv_array_push(&conn->args, ssh);
726-
if (putty && !strcasestr(ssh, "tortoiseplink"))
727-
argv_array_push(&conn->args, "-batch");
728-
if (port) {
729-
/* P is for PuTTY, p is for OpenSSH */
730-
argv_array_push(&conn->args, putty ? "-P" : "-p");
731-
argv_array_push(&conn->args, port);
722+
if (flags & CONNECT_DIAG_URL) {
723+
printf("Diag: url=%s\n", url ? url : "NULL");
724+
printf("Diag: protocol=%s\n", prot_name(protocol));
725+
printf("Diag: userandhost=%s\n", ssh_host ? ssh_host : "NULL");
726+
printf("Diag: port=%s\n", port ? port : "NONE");
727+
printf("Diag: path=%s\n", path ? path : "NULL");
728+
729+
free(hostandport);
730+
free(path);
731+
return NULL;
732+
} else {
733+
if (!ssh) ssh = "ssh";
734+
735+
argv_array_push(&conn->args, ssh);
736+
if (putty && !strcasestr(ssh, "tortoiseplink"))
737+
argv_array_push(&conn->args, "-batch");
738+
if (port) {
739+
/* P is for PuTTY, p is for OpenSSH */
740+
argv_array_push(&conn->args, putty ? "-P" : "-p");
741+
argv_array_push(&conn->args, port);
742+
}
743+
argv_array_push(&conn->args, ssh_host);
732744
}
733-
argv_array_push(&conn->args, ssh_host);
734745
} else {
735746
/* remove repo-local variables from the environment */
736747
conn->env = local_repo_env;

t/t5500-fetch-pack.sh

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,30 @@ check_prot_path () {
541541
test_cmp expected actual
542542
}
543543

544-
check_prot_host_path () {
545-
cat >expected <<-EOF &&
544+
check_prot_host_port_path () {
545+
local diagport
546+
case "$2" in
547+
*ssh*)
548+
pp=ssh
549+
uah=userandhost
550+
ehost=$(echo $3 | tr -d "[]")
551+
diagport="Diag: port=$4"
552+
;;
553+
*)
554+
pp=$p
555+
uah=hostandport
556+
ehost=$(echo $3$4 | sed -e "s/22$/:22/" -e "s/NONE//")
557+
diagport=""
558+
;;
559+
esac
560+
cat >exp <<-EOF &&
546561
Diag: url=$1
547-
Diag: protocol=$2
548-
Diag: hostandport=$3
549-
Diag: path=$4
562+
Diag: protocol=$pp
563+
Diag: $uah=$ehost
564+
$diagport
565+
Diag: path=$5
550566
EOF
567+
grep -v "^$" exp >expected
551568
git fetch-pack --diag-url "$1" >actual &&
552569
test_cmp expected actual
553570
}
@@ -557,22 +574,20 @@ do
557574
# git or ssh with scheme
558575
for p in "ssh+git" "git+ssh" git ssh
559576
do
560-
for h in host host:12 [::1] [::1]:23
577+
for h in host user@host user@[::1] user@::1
561578
do
562-
case "$p" in
563-
*ssh*)
564-
pp=ssh
565-
;;
566-
*)
567-
pp=$p
568-
;;
569-
esac
570579
test_expect_success "fetch-pack --diag-url $p://$h/$r" '
571-
check_prot_host_path $p://$h/$r $pp "$h" "/$r"
580+
check_prot_host_port_path $p://$h/$r $p "$h" NONE "/$r"
572581
'
573582
# "/~" -> "~" conversion
574583
test_expect_success "fetch-pack --diag-url $p://$h/~$r" '
575-
check_prot_host_path $p://$h/~$r $pp "$h" "~$r"
584+
check_prot_host_port_path $p://$h/~$r $p "$h" NONE "~$r"
585+
'
586+
done
587+
for h in host User@host User@[::1]
588+
do
589+
test_expect_success "fetch-pack --diag-url $p://$h:22/$r" '
590+
check_prot_host_port_path $p://$h:22/$r $p "$h" 22 "/$r"
576591
'
577592
done
578593
done
@@ -603,11 +618,11 @@ do
603618
for h in host [::1]
604619
do
605620
test_expect_success "fetch-pack --diag-url $h:$r" '
606-
check_prot_path $h:$r $p "$r"
621+
check_prot_host_port_path $h:$r $p "$h" NONE "$r"
607622
'
608623
# Do "/~" -> "~" conversion
609624
test_expect_success "fetch-pack --diag-url $h:/~$r" '
610-
check_prot_host_path $h:/~$r $p "$h" "~$r"
625+
check_prot_host_port_path $h:/~$r $p "$h" NONE "~$r"
611626
'
612627
done
613628
done

0 commit comments

Comments
 (0)