33
33
using MonoDevelop . Components ;
34
34
using System . Linq ;
35
35
using Mono . Addins ;
36
+ using System . Threading . Tasks ;
36
37
37
38
namespace MonoDevelop . VersionControl . Git
38
39
{
@@ -112,30 +113,13 @@ public static Credentials TryGet (string url, string userFromUrl, SupportedCrede
112
113
{
113
114
bool result = false ;
114
115
Uri uri = null ;
115
-
116
116
GitCredentialsState state ;
117
117
if ( ! credState . TryGetValue ( type , out state ) )
118
118
credState [ type ] = state = new GitCredentialsState ( ) ;
119
119
state . UrlUsed = url ;
120
+ Credentials cred = null ;
120
121
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 ) {
139
123
// Try ssh-agent on Linux.
140
124
if ( ! Platform . IsWindows && ! state . AgentUsed ) {
141
125
bool agentUsable ;
@@ -163,7 +147,7 @@ public static Credentials TryGet (string url, string userFromUrl, SupportedCrede
163
147
} ;
164
148
cred = sshCred ;
165
149
166
- if ( XwtCredentialsDialog . Run ( url , types , cred ) . Result ) {
150
+ if ( XwtCredentialsDialog . Run ( url , SupportedCredentialTypes . Ssh , cred ) . Result ) {
167
151
keyIndex = Keys . IndexOf ( sshCred . PrivateKey ) ;
168
152
if ( keyIndex < 0 ) {
169
153
Keys . Add ( sshCred . PrivateKey ) ;
@@ -186,7 +170,7 @@ public static Credentials TryGet (string url, string userFromUrl, SupportedCrede
186
170
} ;
187
171
188
172
if ( KeyHasPassphrase ( key ) ) {
189
- if ( XwtCredentialsDialog . Run ( url , types , cred ) . Result ) {
173
+ if ( XwtCredentialsDialog . Run ( url , SupportedCredentialTypes . Ssh , cred ) . Result ) {
190
174
var sshCred = ( SshUserKeyCredentials ) cred ;
191
175
keyIndex = Keys . IndexOf ( sshCred . PrivateKey ) ;
192
176
if ( keyIndex < 0 ) {
@@ -202,6 +186,22 @@ public static Credentials TryGet (string url, string userFromUrl, SupportedCrede
202
186
return cred ;
203
187
}
204
188
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
+
205
205
var gitCredentialsProviders = AddinManager . GetExtensionObjects < IGitCredentialsProvider > ( ) ;
206
206
207
207
if ( gitCredentialsProviders != null ) {
@@ -238,7 +238,7 @@ static GitCredentialsProviderResult GetCredentialsFromProvider (IGitCredentialsP
238
238
if ( type != SupportedCredentialTypes . UsernamePassword )
239
239
return GitCredentialsProviderResult . NotFound ;
240
240
241
- var ( result , credentials ) = gitCredentialsProvider . TryGetCredentialsAsync ( uri ) . Result ;
241
+ var ( result , credentials ) = Task . Run ( ( ) => gitCredentialsProvider . TryGetCredentialsAsync ( uri ) ) . Result ;
242
242
243
243
if ( result == GitCredentialsProviderResult . Found ) {
244
244
( ( UsernamePasswordCredentials ) cred ) . Username = credentials . Username ;
0 commit comments