1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-12-15 23:51:36 +02:00

Fix to support creating MRs for repositories cloned with SSH alias (#5082)

### PR Description

Use case: some repositories are cloned with a full SSH alias (without a
user). E.g. in `.ssh/config` you have

```
Host gitlab
    HostName gitlab.com
    User git
    IdentityFile ...
```

and then you clone with `git clone gitlab:foo/bar`

According to the docs, you can add a service to `config.yaml` and it
should work:

```yaml
services:
  gitlab: 'gitlab:gitlab.com'
```

But currently it doesn't because lazygit expects all remote URLs to have
a user. This can be fixed by the user by changing the URL to e.g.
`git@gitlab:foo/bar`, but it breaks the user flow and is quite
unexpected.

This PR changes `defaultUrlRegexStrings` and makes the `user@` part of
the remote URL optional. Fixes the issue for Github and Gitlab which use
the default regexes.
This commit is contained in:
Stefan Haller
2025-12-06 11:58:44 +01:00
committed by GitHub
2 changed files with 21 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ package hosting_service
// at https://regex101.com using the flavor Golang
var defaultUrlRegexStrings = []string{
`^(?:https?|ssh)://[^/]+/(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
`^.*?@.*:/*(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
`^(.*?@)?.*:/*(?P<owner>.*)/(?P<repo>.*?)(?:\.git)?$`,
}
var defaultRepoURLTemplate = "https://{{.webDomain}}/{{.owner}}/{{.repo}}"

View File

@@ -56,6 +56,16 @@ func TestGetPullRequestURL(t *testing.T) {
assert.Equal(t, "https://github.com/peter/calculator/compare/feature%2Fsum-operation?expand=1", url)
},
},
{
testName: "Opens a link to new pull request on github custom SSH config alias and a corresponding service config",
from: "feature/sum-operation",
remoteUrl: "github:peter/calculator.git",
configServiceDomains: map[string]string{"github": "github:github.com"},
test: func(url string, err error) {
assert.NoError(t, err)
assert.Equal(t, "https://github.com/peter/calculator/compare/feature%2Fsum-operation?expand=1", url)
},
},
{
testName: "Opens a link to new pull request on github with extra slash removed",
from: "feature/sum-operation",
@@ -133,6 +143,16 @@ func TestGetPullRequestURL(t *testing.T) {
assert.Equal(t, "https://gitlab.com/peter/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui", url)
},
},
{
testName: "Opens a link to new pull request on gitlab with custom SSH config alias and a corresponding service config",
from: "feature/ui",
remoteUrl: "gitlab:peter/calculator.git",
configServiceDomains: map[string]string{"gitlab": "gitlab:gitlab.com"},
test: func(url string, err error) {
assert.NoError(t, err)
assert.Equal(t, "https://gitlab.com/peter/calculator/-/merge_requests/new?merge_request%5Bsource_branch%5D=feature%2Fui", url)
},
},
{
testName: "Opens a link to new pull request on gitlab with extra slash removed",
from: "feature/ui",