3333using MonoDevelop . Components ;
3434using System . Linq ;
3535using Mono . Addins ;
36+ using System . Threading . Tasks ;
3637
3738namespace MonoDevelop . VersionControl . Git
3839{
@@ -112,30 +113,13 @@ public static Credentials TryGet (string url, string userFromUrl, SupportedCrede
112113 {
113114 bool result = false ;
114115 Uri uri = null ;
115-
116116 GitCredentialsState state ;
117117 if ( ! credState . TryGetValue ( type , out state ) )
118118 credState [ type ] = state = new GitCredentialsState ( ) ;
119119 state . UrlUsed = url ;
120+ Credentials cred = null ;
120121
121- // We always need to run the TryGet* methods as we need the passphraseItem/passwordItem populated even
122- // if the password store contains an invalid password/no password
123- if ( ( types & SupportedCredentialTypes . UsernamePassword ) != 0 ) {
124- if ( Uri . TryCreate ( url , UriKind . RelativeOrAbsolute , out uri ) ) {
125- if ( ! state . NativePasswordUsed && TryGetUsernamePassword ( uri , out var username , out var password ) ) {
126- state . NativePasswordUsed = true ;
127- return new UsernamePasswordCredentials {
128- Username = username ,
129- Password = password
130- } ;
131- }
132- }
133- }
134-
135- Credentials cred ;
136- if ( ( types & SupportedCredentialTypes . UsernamePassword ) != 0 )
137- cred = new UsernamePasswordCredentials ( ) ;
138- else {
122+ if ( ( types & SupportedCredentialTypes . Ssh ) != 0 ) {
139123 // Try ssh-agent on Linux.
140124 if ( ! Platform . IsWindows && ! state . AgentUsed ) {
141125 bool agentUsable ;
@@ -163,7 +147,7 @@ public static Credentials TryGet (string url, string userFromUrl, SupportedCrede
163147 } ;
164148 cred = sshCred ;
165149
166- if ( XwtCredentialsDialog . Run ( url , types , cred ) . Result ) {
150+ if ( XwtCredentialsDialog . Run ( url , SupportedCredentialTypes . Ssh , cred ) . Result ) {
167151 keyIndex = Keys . IndexOf ( sshCred . PrivateKey ) ;
168152 if ( keyIndex < 0 ) {
169153 Keys . Add ( sshCred . PrivateKey ) ;
@@ -186,7 +170,7 @@ public static Credentials TryGet (string url, string userFromUrl, SupportedCrede
186170 } ;
187171
188172 if ( KeyHasPassphrase ( key ) ) {
189- if ( XwtCredentialsDialog . Run ( url , types , cred ) . Result ) {
173+ if ( XwtCredentialsDialog . Run ( url , SupportedCredentialTypes . Ssh , cred ) . Result ) {
190174 var sshCred = ( SshUserKeyCredentials ) cred ;
191175 keyIndex = Keys . IndexOf ( sshCred . PrivateKey ) ;
192176 if ( keyIndex < 0 ) {
@@ -202,6 +186,22 @@ public static Credentials TryGet (string url, string userFromUrl, SupportedCrede
202186 return cred ;
203187 }
204188
189+ // We always need to run the TryGet* methods as we need the passphraseItem/passwordItem populated even
190+ // if the password store contains an invalid password/no password
191+ if ( ( types & SupportedCredentialTypes . UsernamePassword ) != 0 ) {
192+ if ( Uri . TryCreate ( url , UriKind . RelativeOrAbsolute , out uri ) ) {
193+ if ( ! state . NativePasswordUsed && TryGetUsernamePassword ( uri , out var username , out var password ) ) {
194+ state . NativePasswordUsed = true ;
195+ return new UsernamePasswordCredentials {
196+ Username = username ,
197+ Password = password
198+ } ;
199+ }
200+ }
201+ }
202+ if ( cred == null )
203+ cred = new UsernamePasswordCredentials ( ) ;
204+
205205 var gitCredentialsProviders = AddinManager . GetExtensionObjects < IGitCredentialsProvider > ( ) ;
206206
207207 if ( gitCredentialsProviders != null ) {
@@ -238,7 +238,7 @@ static GitCredentialsProviderResult GetCredentialsFromProvider (IGitCredentialsP
238238 if ( type != SupportedCredentialTypes . UsernamePassword )
239239 return GitCredentialsProviderResult . NotFound ;
240240
241- var ( result , credentials ) = gitCredentialsProvider . TryGetCredentialsAsync ( uri ) . Result ;
241+ var ( result , credentials ) = Task . Run ( ( ) => gitCredentialsProvider . TryGetCredentialsAsync ( uri ) ) . Result ;
242242
243243 if ( result == GitCredentialsProviderResult . Found ) {
244244 ( ( UsernamePasswordCredentials ) cred ) . Username = credentials . Username ;
0 commit comments