Skip to content

Commit 9438c32

Browse files
committed
Fix connecting to remote
1 parent d9646e9 commit 9438c32

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

cls/SourceControl/Git/OAuth2.cls

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ ClassMethod GetURLsFromRemote(remote As %String, Output authCodeURL, Output toke
3838
}
3939
}
4040

41-
ClassMethod GetRemoteURLWithToken(token As %String) As %String
41+
ClassMethod SetRemoteURLWithToken(remote As %String) As %String
4242
{
43-
set remote = ""
44-
set url = ##class(SourceControl.Git.Utils).GitRemoteURL()
45-
if url [ "//github.com/" {
46-
set remote = "https://"_token_"@github.com"_$piece(url, "github.com", 2)
47-
} elseif url [ "gitlab" {
48-
set remote = "https://oauth2:"_token_"@gitlab.com"_$piece(url,"https://",2)
43+
set token = ##class(SourceControl.Git.Util.CredentialManager).GetToken($username, .err, .code)
44+
if ('(remote [ token)) {
45+
set post = $piece($piece(remote,"https://",2),"@",2)
46+
set remote = "https://oauth2:"_token_"@"_post
47+
4948
}
5049
return remote
5150
}

cls/SourceControl/Git/Settings.cls

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,6 @@ Method OnAfterConfigure() As %Boolean
497497
$$$ThrowOnError(##class(SourceControl.Git.Utils).AddToSourceControl(##class(SourceControl.Git.Settings.Document).#INTERNALNAME))
498498
$$$ThrowOnError(##class(SourceControl.Git.Utils).Commit(##class(SourceControl.Git.Settings.Document).#INTERNALNAME,"initial commit"))
499499
}
500-
// Set remote to remove token
501-
do ##class(SourceControl.Git.Utils).SetConfiguredRemote(..gitRemoteURL)
502500
}
503501
}
504502
}

cls/SourceControl/Git/Utils.cls

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,7 @@ ClassMethod Clone(remote As %String) As %Status
676676
set settings = ##class(SourceControl.Git.Settings).%New()
677677
// Modify remote if using https
678678
if (remote [ "https") {
679-
set token = ##class(SourceControl.Git.Util.CredentialManager).GetToken($username, .err, .code)
680-
set remote = ##class(SourceControl.Git.OAuth2).GetRemoteURLWithToken(token)
679+
set remote = ##class(SourceControl.Git.OAuth2).SetRemoteURLWithToken(remote)
681680
}
682681
// TODO: eventually use /ENV flag with GIT_TERMINAL_PROMPT=0. (This isn't doc'd yet and is only in really new versions.)
683682
set sc = ..RunGitWithArgs(.errStream, .outStream, "clone", remote, settings.namespaceTemp)
@@ -1878,9 +1877,11 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
18781877

18791878
if ((..GitRemoteType() = "HTTPS") && ((command = "pull") || (command = "push") || (command = "fetch"))) {
18801879
// Need to use token
1881-
set token = ##class(SourceControl.Git.Util.CredentialManager).GetToken($username,.err,.code)
1882-
set url = ##class(SourceControl.Git.OAuth2).GetRemoteURLWithToken(token)
1883-
set newArgs($increment(newArgs)) = url
1880+
set remote = ..GetConfiguredRemote()
1881+
set tokenURL = ##class(SourceControl.Git.OAuth2).SetRemoteURLWithToken(remote)
1882+
if (remote '= tokenURL) {
1883+
do ..SetConfiguredRemote(tokenURL)
1884+
}
18841885
}
18851886

18861887
set syncIrisWithDiff = 0 // whether IRIS needs to be synced with repo file changes using diff output

0 commit comments

Comments
 (0)