public GitActionResult<GitBranchInfo> Checkout(GitBranchInfo info, bool force = false)
{
using (var repository = GetRepository())
{
var result = new GitActionResult<GitBranchInfo>();
CheckoutOptions options = new CheckoutOptions();
var branch = repository.Branches.FirstOrDefault(
x => string.Equals(x.CanonicalName, info.CanonicalName, StringComparison.OrdinalIgnoreCase));
if (force)
{
options.CheckoutModifiers = CheckoutModifiers.Force;
}
try
{
var checkoutBranch = repository.Checkout(branch, options);
if (checkoutBranch != null)
{
result.Item = new GitBranchInfo
{
CanonicalName = checkoutBranch.CanonicalName,
RemoteName = checkoutBranch.Remote?.Name,
Name = checkoutBranch.FriendlyName,
IsRemote = checkoutBranch.IsRemote
};
result.Succeeded = true;
return result;
}
result.Succeeded = false;
}
catch (CheckoutConflictException conflict)
{
result.Succeeded = false;
result.ErrorMessage = conflict.Message;
}
return result;
}
}