using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using LibGit2Sharp.Core;
using LibGit2Sharp.Handlers;
namespace LibGit2Sharp
{
///
/// Provides helper overloads to a .
///
public static class NetworkExtensions
{
///
/// Push the specified branch to its tracked branch on the remote.
///
/// The being worked with.
/// The branch to push.
/// controlling push behavior
/// Throws if either the Remote or the UpstreamBranchCanonicalName is not set.
public static void Push(
this Network network,
Branch branch,
PushOptions pushOptions = null)
{
network.Push(new[] { branch }, pushOptions);
}
///
/// Push the specified branches to their tracked branches on the remote.
///
/// The being worked with.
/// The branches to push.
/// controlling push behavior
/// Throws if either the Remote or the UpstreamBranchCanonicalName is not set.
public static void Push(
this Network network,
IEnumerable branches,
PushOptions pushOptions = null)
{
var enumeratedBranches = branches as IList ?? branches.ToList();
foreach (var branch in enumeratedBranches)
{
if (string.IsNullOrEmpty(branch.UpstreamBranchCanonicalName))
{
throw new LibGit2SharpException(
string.Format(
CultureInfo.InvariantCulture,
"The branch '{0}' (\"{1}\") that you are trying to push does not track an upstream branch.",
branch.Name, branch.CanonicalName));
}
}
foreach (var branch in enumeratedBranches)
{
network.Push(branch.Remote, string.Format(
CultureInfo.InvariantCulture,
"{0}:{1}", branch.CanonicalName, branch.UpstreamBranchCanonicalName), pushOptions);
}
}
}
}