Skip to content

Commit

Permalink
t5500: show user name and host in diag-url
Browse files Browse the repository at this point in the history
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 <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Torsten Bögershausen authored and Junio C Hamano committed Feb 22, 2015
1 parent 9f69765 commit 3f55cca
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 30 deletions.
35 changes: 23 additions & 12 deletions connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ struct child_process *git_connect(int fd[2], const char *url,
signal(SIGCHLD, SIG_DFL);

protocol = parse_connect_url(url, &hostandport, &path);
if (flags & CONNECT_DIAG_URL) {
if ((flags & CONNECT_DIAG_URL) && (protocol != PROTO_SSH)) {
printf("Diag: url=%s\n", url ? url : "NULL");
printf("Diag: protocol=%s\n", prot_name(protocol));
printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
Expand Down Expand Up @@ -719,18 +719,29 @@ struct child_process *git_connect(int fd[2], const char *url,
get_host_and_port(&ssh_host, &port);
if (!port)
port = get_port(ssh_host);

if (!ssh) ssh = "ssh";

argv_array_push(&conn->args, ssh);
if (putty && !strcasestr(ssh, "tortoiseplink"))
argv_array_push(&conn->args, "-batch");
if (port) {
/* P is for PuTTY, p is for OpenSSH */
argv_array_push(&conn->args, putty ? "-P" : "-p");
argv_array_push(&conn->args, port);
if (flags & CONNECT_DIAG_URL) {
printf("Diag: url=%s\n", url ? url : "NULL");
printf("Diag: protocol=%s\n", prot_name(protocol));
printf("Diag: userandhost=%s\n", ssh_host ? ssh_host : "NULL");
printf("Diag: port=%s\n", port ? port : "NONE");
printf("Diag: path=%s\n", path ? path : "NULL");

free(hostandport);
free(path);
return NULL;
} else {
if (!ssh) ssh = "ssh";

argv_array_push(&conn->args, ssh);
if (putty && !strcasestr(ssh, "tortoiseplink"))
argv_array_push(&conn->args, "-batch");
if (port) {
/* P is for PuTTY, p is for OpenSSH */
argv_array_push(&conn->args, putty ? "-P" : "-p");
argv_array_push(&conn->args, port);
}
argv_array_push(&conn->args, ssh_host);
}
argv_array_push(&conn->args, ssh_host);
} else {
/* remove repo-local variables from the environment */
conn->env = local_repo_env;
Expand Down
51 changes: 33 additions & 18 deletions t/t5500-fetch-pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,30 @@ check_prot_path () {
test_cmp expected actual
}

check_prot_host_path () {
cat >expected <<-EOF &&
check_prot_host_port_path () {
local diagport
case "$2" in
*ssh*)
pp=ssh
uah=userandhost
ehost=$(echo $3 | tr -d "[]")
diagport="Diag: port=$4"
;;
*)
pp=$p
uah=hostandport
ehost=$(echo $3$4 | sed -e "s/22$/:22/" -e "s/NONE//")
diagport=""
;;
esac
cat >exp <<-EOF &&
Diag: url=$1
Diag: protocol=$2
Diag: hostandport=$3
Diag: path=$4
Diag: protocol=$pp
Diag: $uah=$ehost
$diagport
Diag: path=$5
EOF
grep -v "^$" exp >expected
git fetch-pack --diag-url "$1" >actual &&
test_cmp expected actual
}
Expand All @@ -557,22 +574,20 @@ do
# git or ssh with scheme
for p in "ssh+git" "git+ssh" git ssh
do
for h in host host:12 [::1] [::1]:23
for h in host user@host user@[::1] user@::1
do
case "$p" in
*ssh*)
pp=ssh
;;
*)
pp=$p
;;
esac
test_expect_success "fetch-pack --diag-url $p://$h/$r" '
check_prot_host_path $p://$h/$r $pp "$h" "/$r"
check_prot_host_port_path $p://$h/$r $p "$h" NONE "/$r"
'
# "/~" -> "~" conversion
test_expect_success "fetch-pack --diag-url $p://$h/~$r" '
check_prot_host_path $p://$h/~$r $pp "$h" "~$r"
check_prot_host_port_path $p://$h/~$r $p "$h" NONE "~$r"
'
done
for h in host User@host User@[::1]
do
test_expect_success "fetch-pack --diag-url $p://$h:22/$r" '
check_prot_host_port_path $p://$h:22/$r $p "$h" 22 "/$r"
'
done
done
Expand Down Expand Up @@ -603,11 +618,11 @@ do
for h in host [::1]
do
test_expect_success "fetch-pack --diag-url $h:$r" '
check_prot_path $h:$r $p "$r"
check_prot_host_port_path $h:$r $p "$h" NONE "$r"
'
# Do "/~" -> "~" conversion
test_expect_success "fetch-pack --diag-url $h:/~$r" '
check_prot_host_path $h:/~$r $p "$h" "~$r"
check_prot_host_port_path $h:/~$r $p "$h" NONE "~$r"
'
done
done
Expand Down

0 comments on commit 3f55cca

Please sign in to comment.