Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion git-open
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,13 @@ else
if [[ -e "$ssh_config" ]]; then
domain_resolv=$(ssh_resolve "$domain")
if [[ -n "$domain_resolv" ]]; then
domain="$domain_resolv"
# Don't use ssh.* subdomains for web URLs (e.g., ssh.github.com)
if [[ $domain != ssh.* && $domain_resolv == ssh.* ]]; then
# Keep the original domain instead of using ssh.* subdomain
:
else
domain="$domain_resolv"
fi
fi
fi
fi
Expand Down
20 changes: 20 additions & 0 deletions test/git-open.bats
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,26 @@ setup() {
assert_output "https://override.zero.com/user/repo"
}

@test "sshconfig: ssh subdomain endpoints should not be used for web URLs" {
# When SSH config maps github.com -> ssh.github.com (for SSH over HTTPS port 443),
# the web URL should still use github.com, not ssh.github.com
# See: https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port
create_ssh_sandbox

# Add github.com -> ssh.github.com mapping to SSH config
echo "
Host github.com
HostName ssh.github.com
Port 443
User git
" >> $ssh_config

git remote set-url origin "git@github.com:rails/rails.git"
run ../git-open
# Should use github.com for web URL, NOT ssh.github.com
assert_output "https://github.com/rails/rails"
}

##
## Bitbucket
##
Expand Down