fix(cmdutils): say how to set ssh_host when a remote is on a subdomain of a logged-in host

Description

In a clone whose SSH remote is on an instance's separate SSH host, such as ssh.gitlab.gnome.org for gitlab.gnome.org, repository commands fail when ssh_host is unset. The error says to run glab auth login, which doesn't help if you already have.

When an SSH remote host is a subdomain of a configured host, the error now names the command that links them, instead of suggesting glab auth login. glab doesn't map such a remote by itself, since the subdomain may be a separate instance (see #8707). Before:

none of the git remotes configured for this repository point to a known GitLab host. Please use `glab auth login` to authenticate and configure a new host for glab.

Configured remotes: ssh.gitlab.gnome.org.

After:

none of the git remotes configured for this repository point to a known GitLab host.

If ssh.gitlab.gnome.org is the SSH host of gitlab.gnome.org, run:

  glab config set ssh_host ssh.gitlab.gnome.org --host gitlab.gnome.org

Configured remotes: ssh.gitlab.gnome.org.

HTTPS remotes get no hint. A subdomain in an HTTPS remote is a separate web address, and so most likely a separate instance, and setting ssh_host to it would send that remote's requests to the parent host. Errors without a hint are unchanged.

Part of #8707.

How has this been tested?

New cases in Test_remoteResolverErrors:

  • Two SSH remotes on ssh.my-gitlab.org give one hint for the configured my-gitlab.org.
  • An SSH remote on notmy-gitlab.org gives no hint.
  • An HTTPS remote on dev.my-gitlab.org gives no hint.
  • With both my-gitlab.org and gitlab.my-gitlab.org configured, ssh.gitlab.my-gitlab.org is matched to gitlab.my-gitlab.org.

Also:

  • In a clone of GNOME/gnome-settings-daemon (remote git@ssh.gitlab.gnome.org:..., ssh_host unset), glab issue list prints the error above. Running the suggested command in a copy of the config makes glab issue list list the issues.
  • go test ./internal/cmdutils/, make test-changed and golangci-lint run ./internal/cmdutils/... pass. The comment-overlap gate reports nothing for the new code.
Edited by Johan Walles

Merge request reports

Loading
Loading