mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
fix(git): support azure devops remote URL
This commit is contained in:
parent
58ba3b075c
commit
7836a240f1
|
@ -451,6 +451,14 @@ func (g *Git) setBranchStatus() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Git) cleanUpstreamURL(url string) string {
|
func (g *Git) cleanUpstreamURL(url string) string {
|
||||||
|
// https://{organization}@dev.azure.com/{organization}/{project}/_git/{repository}
|
||||||
|
if strings.Contains(url, "@dev.azure.com") {
|
||||||
|
match := regex.FindNamedRegexMatch(`.*@(?P<URL>dev.azure.com.*)`, url)
|
||||||
|
if len(match) != 0 {
|
||||||
|
return fmt.Sprintf("https://%s", match["URL"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(url, "http") {
|
if strings.HasPrefix(url, "http") {
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
|
@ -649,11 +649,12 @@ func TestGitCleanSSHURL(t *testing.T) {
|
||||||
{Case: "gitea no port, no user", Expected: "https://src.example.com/user/repo", Upstream: "_gitea@src.example.com:user/repo.git"},
|
{Case: "gitea no port, no user", Expected: "https://src.example.com/user/repo", Upstream: "_gitea@src.example.com:user/repo.git"},
|
||||||
{Case: "git@ with user", Expected: "https://github.com/JanDeDobbeleer/oh-my-posh", Upstream: "git@github.com:JanDeDobbeleer/oh-my-posh"},
|
{Case: "git@ with user", Expected: "https://github.com/JanDeDobbeleer/oh-my-posh", Upstream: "git@github.com:JanDeDobbeleer/oh-my-posh"},
|
||||||
{Case: "unsupported", Upstream: "\\test\\repo.git"},
|
{Case: "unsupported", Upstream: "\\test\\repo.git"},
|
||||||
|
{Case: "Azure DevOps", Expected: "https://dev.azure.com/posh/oh-my-posh/_git/website", Upstream: "https://posh@dev.azure.com/posh/oh-my-posh/_git/website"},
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
g := &Git{}
|
g := &Git{}
|
||||||
upstreamIcon := g.cleanUpstreamURL(tc.Upstream)
|
upstreamURL := g.cleanUpstreamURL(tc.Upstream)
|
||||||
assert.Equal(t, tc.Expected, upstreamIcon, tc.Case)
|
assert.Equal(t, tc.Expected, upstreamURL, tc.Case)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue