Skip to content

Commit

Permalink
fix(git): support azure devops remote URL - SSH
Browse files Browse the repository at this point in the history
  • Loading branch information
hsnabszhdn authored and JanDeDobbeleer committed Sep 8, 2024
1 parent 7836a24 commit f1e74fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/segments/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,11 @@ func (g *Git) setBranchStatus() {
}

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"])
// Azure DevOps
if strings.Contains(url, "dev.azure.com") {
match := regex.FindNamedRegexMatch(`^.*@(ssh.)?dev\.azure\.com(:v3)?/(?P<ORGANIZATION>[A-Za-z0-9_-]+)/(?P<PROJECT>[A-Za-z0-9_-]+)/(_git/)?(?P<REPOSITORY>[A-Za-z0-9_-]+)$`, url)
if len(match) == 4 {
return fmt.Sprintf("https://dev.azure.com/%s/%s/_git/%s", match["ORGANIZATION"], match["PROJECT"], match["REPOSITORY"])
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/segments/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,8 @@ func TestGitCleanSSHURL(t *testing.T) {
{Case: "gitea no port, no user", Expected: "https://src.example.com/user/repo", Upstream: "[email protected]:user/repo.git"},
{Case: "git@ with user", Expected: "https://github.com/JanDeDobbeleer/oh-my-posh", Upstream: "[email protected]:JanDeDobbeleer/oh-my-posh"},
{Case: "unsupported", Upstream: "\\test\\repo.git"},
{Case: "Azure DevOps", Expected: "https://dev.azure.com/posh/oh-my-posh/_git/website", Upstream: "https://[email protected]/posh/oh-my-posh/_git/website"},
{Case: "Azure DevOps, https", Expected: "https://dev.azure.com/posh/oh-my-posh/_git/website", Upstream: "https://[email protected]/posh/oh-my-posh/_git/website"},
{Case: "Azure DevOps, ssh", Expected: "https://dev.azure.com/posh/oh-my-posh/_git/website", Upstream: "[email protected]:v3/posh/oh-my-posh/website"},
}
for _, tc := range cases {
g := &Git{}
Expand Down

0 comments on commit f1e74fe

Please sign in to comment.