@@ -332,6 +332,72 @@ public virtual void Fetch(
332
332
DoFetch ( repository . Handle , url , options , logMessage , refspecs ) ;
333
333
}
334
334
335
+ /// <summary>
336
+ /// Push the specified branch to its tracked branch on the remote.
337
+ /// </summary>
338
+ /// <param name="branch">The branch to push.</param>
339
+ /// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception>
340
+ public virtual void Push (
341
+ Branch branch )
342
+ {
343
+ Push ( new [ ] { branch } ) ;
344
+ }
345
+ /// <summary>
346
+ /// Push the specified branch to its tracked branch on the remote.
347
+ /// </summary>
348
+ /// <param name="branch">The branch to push.</param>
349
+ /// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
350
+ /// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception>
351
+ public virtual void Push (
352
+ Branch branch ,
353
+ PushOptions pushOptions )
354
+ {
355
+ Push ( new [ ] { branch } , pushOptions ) ;
356
+ }
357
+
358
+ /// <summary>
359
+ /// Push the specified branches to their tracked branches on the remote.
360
+ /// </summary>
361
+ /// <param name="branches">The branches to push.</param>
362
+ /// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception>
363
+ public virtual void Push (
364
+ IEnumerable < Branch > branches )
365
+ {
366
+ Push ( branches , null ) ;
367
+ }
368
+
369
+ /// <summary>
370
+ /// Push the specified branches to their tracked branches on the remote.
371
+ /// </summary>
372
+ /// <param name="branches">The branches to push.</param>
373
+ /// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
374
+ /// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception>
375
+ public virtual void Push (
376
+ IEnumerable < Branch > branches ,
377
+ PushOptions pushOptions )
378
+ {
379
+ var enumeratedBranches = branches as IList < Branch > ?? branches . ToList ( ) ;
380
+
381
+ foreach ( var branch in enumeratedBranches )
382
+ {
383
+ if ( string . IsNullOrEmpty ( branch . UpstreamBranchCanonicalName ) )
384
+ {
385
+ throw new LibGit2SharpException (
386
+ string . Format (
387
+ CultureInfo . InvariantCulture ,
388
+ "The branch '{0}' (\" {1}\" ) that you are trying to push does not track an upstream branch." ,
389
+ branch . FriendlyName , branch . CanonicalName ) ) ;
390
+ }
391
+ }
392
+
393
+ foreach ( var branch in enumeratedBranches )
394
+ {
395
+ Push ( branch . Remote , string . Format (
396
+ CultureInfo . InvariantCulture ,
397
+ "{0}:{1}" , branch . CanonicalName , branch . UpstreamBranchCanonicalName ) , pushOptions ) ;
398
+ }
399
+ }
400
+
335
401
/// <summary>
336
402
/// Push the objectish to the destination reference on the <see cref="Remote"/>.
337
403
/// </summary>
0 commit comments