@@ -150,12 +150,7 @@ static string CreateDynamicRepository(string targetPath, Authentication authenti
150
150
151
151
Logger . WriteInfo ( string . Format ( "Retrieving git info from url '{0}'" , repositoryUrl ) ) ;
152
152
153
- Repository . Clone ( repositoryUrl , gitDirectory ,
154
- new CloneOptions
155
- {
156
- Checkout = false ,
157
- CredentialsProvider = ( url , usernameFromUrl , types ) => credentials
158
- } ) ;
153
+ CloneRepository ( repositoryUrl , gitDirectory , credentials ) ;
159
154
160
155
// Normalize (download branches) before using the branch
161
156
GitHelper . NormalizeGitDirectory ( gitDirectory , authentication , noFetch ) ;
@@ -200,6 +195,38 @@ static string CreateDynamicRepository(string targetPath, Authentication authenti
200
195
return gitDirectory ;
201
196
}
202
197
198
+ private static void CloneRepository ( string repositoryUrl , string gitDirectory , Credentials credentials )
199
+ {
200
+ try
201
+ {
202
+ Repository . Clone ( repositoryUrl , gitDirectory ,
203
+ new CloneOptions
204
+ {
205
+ Checkout = false ,
206
+ CredentialsProvider = ( url , usernameFromUrl , types ) => credentials
207
+ } ) ;
208
+ }
209
+ catch ( LibGit2SharpException ex )
210
+ {
211
+ var message = ex . Message ;
212
+ if ( message . Contains ( "401" ) )
213
+ {
214
+ throw new Exception ( "Unauthorised: Incorrect username/password" ) ;
215
+ }
216
+ if ( message . Contains ( "403" ) )
217
+ {
218
+ throw new Exception ( "Forbidden: Possbily Incorrect username/password" ) ;
219
+ }
220
+ if ( message . Contains ( "404" ) )
221
+ {
222
+ throw new Exception ( "Not found: The repository was not found" ) ;
223
+ }
224
+
225
+ throw new Exception ( "There was an unknown problem with the Git repository you provided" ) ;
226
+
227
+ }
228
+ }
229
+
203
230
private static Reference GetLocalReference ( Repository repository , string branchName )
204
231
{
205
232
var targetBranchName = branchName . GetCanonicalBranchName ( ) ;
0 commit comments