@@ -81,9 +81,21 @@ public int CertificateCheck(Certificate cert, bool valid, string hostname)
8181 Marshal . FreeHGlobal ( certPtr ) ;
8282 }
8383
84+ if ( ret > 0 )
85+ {
86+ ret = valid ? 0 : - 1 ;
87+ }
88+
8489 return ret ;
8590 }
8691
92+ /// <summary>
93+ /// Call the credential acquisition callback
94+ /// </summary>
95+ /// <param name="cred">Credential data to populate</param>
96+ /// <param name="user">Username from the URL, if any</param>
97+ /// <param name="methods">Supported methods</param>
98+ /// <returns></returns>
8799 public int AcquireCredentials ( out Credentials cred , string user , params Type [ ] methods )
88100 {
89101 // Convert the user-provided types to libgit2's flags
@@ -127,6 +139,12 @@ public int AcquireCredentials(out Credentials cred, string user, params Type[] m
127139 }
128140 }
129141
142+ /// <summary>
143+ /// libgit2 will call an action back with a null url to indicate that
144+ /// it should re-use the prior url; store the url so that we can replay.
145+ /// </summary>
146+ private string LastActionUrl { get ; set ; }
147+
130148 /// <summary>
131149 /// Invoked by libgit2 to create a connection using this subtransport.
132150 /// </summary>
@@ -202,43 +220,57 @@ private static int Action(
202220 SmartSubtransport t = GCHandle . FromIntPtr ( Marshal . ReadIntPtr ( subtransport , GitSmartSubtransport . GCHandleOffset ) ) . Target as SmartSubtransport ;
203221 String urlAsString = LaxUtf8Marshaler . FromNative ( url ) ;
204222
205- if ( null != t &&
206- ! String . IsNullOrEmpty ( urlAsString ) )
223+ if ( t == null )
207224 {
208- try
209- {
210- stream = t . Action ( urlAsString , action ) . GitSmartTransportStreamPointer ;
225+ Proxy . giterr_set_str ( GitErrorCategory . Net , "no subtransport provided" ) ;
226+ return ( int ) GitErrorCode . Error ;
227+ }
211228
212- return 0 ;
213- }
214- catch ( Exception ex )
215- {
216- Proxy . giterr_set_str ( GitErrorCategory . Net , ex ) ;
217- }
229+ if ( String . IsNullOrEmpty ( urlAsString ) )
230+ {
231+ urlAsString = t . LastActionUrl ;
232+ }
233+
234+ if ( String . IsNullOrEmpty ( urlAsString ) )
235+ {
236+ Proxy . giterr_set_str ( GitErrorCategory . Net , "no url provided" ) ;
237+ return ( int ) GitErrorCode . Error ;
218238 }
219239
220- return ( int ) GitErrorCode . Error ;
240+ try
241+ {
242+ stream = t . Action ( urlAsString , action ) . GitSmartTransportStreamPointer ;
243+ t . LastActionUrl = urlAsString ;
244+ return 0 ;
245+ }
246+ catch ( Exception ex )
247+ {
248+ Proxy . giterr_set_str ( GitErrorCategory . Net , ex ) ;
249+ return ( int ) GitErrorCode . Error ;
250+ }
221251 }
222252
223253 private static int Close ( IntPtr subtransport )
224254 {
225255 SmartSubtransport t = GCHandle . FromIntPtr ( Marshal . ReadIntPtr ( subtransport , GitSmartSubtransport . GCHandleOffset ) ) . Target as SmartSubtransport ;
226256
227- if ( null != t )
257+ if ( t == null )
228258 {
229- try
230- {
231- t . Close ( ) ;
232-
233- return 0 ;
234- }
235- catch ( Exception ex )
236- {
237- Proxy . giterr_set_str ( GitErrorCategory . Net , ex ) ;
238- }
259+ Proxy . giterr_set_str ( GitErrorCategory . Net , "no subtransport provided" ) ;
260+ return ( int ) GitErrorCode . Error ;
239261 }
240262
241- return ( int ) GitErrorCode . Error ;
263+ try
264+ {
265+ t . Close ( ) ;
266+
267+ return 0 ;
268+ }
269+ catch ( Exception ex )
270+ {
271+ Proxy . giterr_set_str ( GitErrorCategory . Net , ex ) ;
272+ return ( int ) GitErrorCode . Error ;
273+ }
242274 }
243275
244276 private static void Free ( IntPtr subtransport )
0 commit comments