Skip to content

Commit ca14e7a

Browse files
committed
Fold NetworkExtensions.cs into Network.cs
1 parent d047e2f commit ca14e7a

File tree

3 files changed

+66
-87
lines changed

3 files changed

+66
-87
lines changed

LibGit2Sharp/LibGit2Sharp.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@
242242
<Compile Include="CheckoutConflictException.cs" />
243243
<Compile Include="MergeHead.cs" />
244244
<Compile Include="NameConflictException.cs" />
245-
<Compile Include="NetworkExtensions.cs" />
246245
<Compile Include="NonFastForwardException.cs" />
247246
<Compile Include="PushResult.cs" />
248247
<Compile Include="PushStatusError.cs" />

LibGit2Sharp/Network.cs

+66
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,72 @@ public virtual void Fetch(
332332
DoFetch(repository.Handle, url, options, logMessage, refspecs);
333333
}
334334

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+
335401
/// <summary>
336402
/// Push the objectish to the destination reference on the <see cref="Remote"/>.
337403
/// </summary>

LibGit2Sharp/NetworkExtensions.cs

-86
This file was deleted.

0 commit comments

Comments
 (0)