-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
393 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
using System; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using Cake.Core; | ||
using Cake.Core.Annotations; | ||
using Cake.Core.IO; | ||
using Cake.Git.Extensions; | ||
using LibGit2Sharp; | ||
|
||
// ReSharper disable MemberCanBePrivate.Global | ||
// ReSharper disable UnusedMember.Global | ||
namespace Cake.Git | ||
{ | ||
// ReSharper disable once PublicMembersMustHaveComments | ||
public static partial class GitAliases | ||
{ | ||
/// <summary> | ||
/// Pull unauthenticated using default options. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Repository path.</param> | ||
/// <param name="mergerName">The name of the merger.</param> | ||
/// <param name="mergerEmail">The email of the merger.</param> | ||
/// <returns>The path to the created repository.</returns> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Pull")] | ||
public static GitMergeResult GitPull( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
string mergerName, | ||
string mergerEmail | ||
) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath == null) | ||
{ | ||
throw new ArgumentNullException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
var workFullDirectoryPath = repositoryDirectoryPath.MakeAbsolute(context.Environment); | ||
|
||
if (!context.FileSystem.Exist(workFullDirectoryPath)) | ||
{ | ||
throw new DirectoryNotFoundException($"Failed to find workDirectoryPath: {workFullDirectoryPath}"); | ||
} | ||
|
||
return new GitMergeResult( | ||
context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository => | ||
repository.Network.Pull( | ||
new Signature( | ||
mergerName, | ||
mergerEmail, | ||
DateTimeOffset.Now | ||
), | ||
new PullOptions() | ||
) | ||
) | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// Pull authenticating using default options. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Repository path.</param> | ||
/// <param name="mergerName">The name of the merger.</param> | ||
/// <param name="mergerEmail">The email of the merger.</param> | ||
/// <param name="username">Username used for authentication.</param> | ||
/// <param name="password">Password used for authentication.</param> | ||
/// <param name="remoteName">Name of remote to pull from.</param> | ||
/// <returns>The path to the created repository.</returns> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Pull")] | ||
public static GitMergeResult GitPull( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
string mergerName, | ||
string mergerEmail, | ||
string username, | ||
string password, | ||
string remoteName | ||
) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath == null) | ||
{ | ||
throw new ArgumentNullException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
var repositoryFullDirectoryPath = repositoryDirectoryPath.MakeAbsolute(context.Environment); | ||
|
||
if (!context.FileSystem.Exist(repositoryFullDirectoryPath)) | ||
{ | ||
throw new DirectoryNotFoundException($"Failed to find repositoryDirectoryPath: {repositoryFullDirectoryPath}"); | ||
} | ||
|
||
return new GitMergeResult( | ||
context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository => | ||
{ | ||
var remote = repository.Network.Remotes[remoteName]; | ||
if (remote == null) | ||
{ | ||
throw new NotFoundException("Remote named {0} not found", remoteName); | ||
} | ||
|
||
repository.Network.Fetch( | ||
remote, | ||
new FetchOptions | ||
{ | ||
CredentialsProvider = | ||
(url, usernameFromUrl, types) => | ||
new UsernamePasswordCredentials | ||
{ | ||
Username = username, | ||
Password = password | ||
} | ||
} | ||
); | ||
|
||
return repository.MergeFetchedRefs( | ||
new Signature( | ||
mergerName, | ||
mergerEmail, | ||
DateTimeOffset.Now | ||
), | ||
new MergeOptions() | ||
); | ||
} | ||
) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
using System; | ||
using System.IO; | ||
using Cake.Core; | ||
using Cake.Core.Annotations; | ||
using Cake.Core.IO; | ||
using Cake.Git.Extensions; | ||
using LibGit2Sharp; | ||
|
||
// ReSharper disable MemberCanBePrivate.Global | ||
// ReSharper disable UnusedMember.Global | ||
namespace Cake.Git | ||
{ | ||
// ReSharper disable once PublicMembersMustHaveComments | ||
public static partial class GitAliases | ||
{ | ||
/// <summary> | ||
/// Push all branches unauthenticated. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Repository path.</param> | ||
/// <returns>The path to the created repository.</returns> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Push")] | ||
public static void GitPush( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath | ||
) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath == null) | ||
{ | ||
throw new ArgumentNullException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
var workFullDirectoryPath = repositoryDirectoryPath.MakeAbsolute(context.Environment); | ||
|
||
if (!context.FileSystem.Exist(workFullDirectoryPath)) | ||
{ | ||
throw new DirectoryNotFoundException($"Failed to find workDirectoryPath: {workFullDirectoryPath}"); | ||
} | ||
|
||
context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository => | ||
repository.Network.Push( | ||
repository.Branches | ||
) | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// Push all branches authenticated. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Repository path.</param> | ||
/// <param name="username">Username used for authentication.</param> | ||
/// <param name="password">Password used for authentication.</param> | ||
/// <returns>The path to the created repository.</returns> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Push")] | ||
public static void GitPush( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
string username, | ||
string password | ||
) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath == null) | ||
{ | ||
throw new ArgumentNullException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
var repositoryFullDirectoryPath = repositoryDirectoryPath.MakeAbsolute(context.Environment); | ||
|
||
if (!context.FileSystem.Exist(repositoryFullDirectoryPath)) | ||
{ | ||
throw new DirectoryNotFoundException($"Failed to find repositoryDirectoryPath: {repositoryFullDirectoryPath}"); | ||
} | ||
|
||
context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository => | ||
repository.Network.Push( | ||
repository.Branches, | ||
new PushOptions | ||
{ | ||
CredentialsProvider = | ||
(url, usernameFromUrl, types) => | ||
new UsernamePasswordCredentials | ||
{ | ||
Username = username, | ||
Password = password | ||
} | ||
} | ||
) | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// Push specific branch authenticated. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Repository path.</param> | ||
/// <param name="username">Username used for authentication.</param> | ||
/// <param name="password">Password used for authentication.</param> | ||
/// <param name="branchName">Name of branch to push.</param> | ||
/// <returns>The path to the created repository.</returns> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Push")] | ||
public static void GitPush( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
string username, | ||
string password, | ||
string branchName | ||
) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath == null) | ||
{ | ||
throw new ArgumentNullException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
var repositoryFullDirectoryPath = repositoryDirectoryPath.MakeAbsolute(context.Environment); | ||
|
||
if (!context.FileSystem.Exist(repositoryFullDirectoryPath)) | ||
{ | ||
throw new DirectoryNotFoundException($"Failed to find repositoryDirectoryPath: {repositoryFullDirectoryPath}"); | ||
} | ||
|
||
context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository => | ||
{ | ||
var branch = repository.Branches[branchName]; | ||
if (branch == null) | ||
{ | ||
throw new NotFoundException("Failed to find branch {0}", branchName); | ||
} | ||
|
||
repository.Network.Push( | ||
branch, | ||
new PushOptions | ||
{ | ||
CredentialsProvider = | ||
(url, usernameFromUrl, types) => | ||
new UsernamePasswordCredentials | ||
{ | ||
Username = username, | ||
Password = password | ||
} | ||
} | ||
); | ||
} | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using LibGit2Sharp; | ||
// ReSharper disable MemberCanBePrivate.Global | ||
|
||
namespace Cake.Git | ||
{ | ||
/// <summary> | ||
/// Git repository merge operation result | ||
/// </summary> | ||
public sealed class GitMergeResult | ||
{ | ||
/// <summary> | ||
/// Merge commit. | ||
/// </summary> | ||
public GitCommit Commit { get; } | ||
|
||
/// <summary> | ||
/// Merge status | ||
/// </summary> | ||
public GitMergeStatus Status { get; } | ||
|
||
internal GitMergeResult(MergeResult mergeResult) | ||
{ | ||
if (mergeResult == null) | ||
{ | ||
throw new ArgumentNullException(nameof(mergeResult)); | ||
} | ||
|
||
Commit = new GitCommit(mergeResult.Commit); | ||
Status = (GitMergeStatus) mergeResult.Status; | ||
} | ||
} | ||
} |
Oops, something went wrong.