-
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
3 changed files
with
174 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,6 @@ string message | |
) | ||
) | ||
); | ||
|
||
} | ||
} | ||
} |
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,173 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
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> | ||
/// Get last commit | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Path to repository.</param> | ||
/// <returns>The path to the created repository.</returns> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Log")] | ||
[CakeNamespaceImport("LibGit2Sharp")] | ||
public static GitCommit GitLogTip( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath | ||
) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath == null) | ||
{ | ||
throw new ArgumentNullException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
return context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository => new GitCommit(repository.Head.Tip) | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// Get commit log. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Path to repository.</param> | ||
/// <param name="count">Number of commits to fetch.</param> | ||
/// <returns>The path to the created repository.</returns> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Log")] | ||
[CakeNamespaceImport("LibGit2Sharp")] | ||
public static ICollection<GitCommit> GitLog( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
int count | ||
) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath == null) | ||
{ | ||
throw new ArgumentNullException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
return context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository => repository.Commits | ||
.Take(count) | ||
.Select(commit => new GitCommit(commit)) | ||
.ToList() | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// Get commit from certain commit id up to current. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Path to repository.</param> | ||
/// <param name="sinceCommitId">Commit id to start fetching from.</param> | ||
/// <returns>The path to the created repository.</returns> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Log")] | ||
[CakeNamespaceImport("LibGit2Sharp")] | ||
public static ICollection<GitCommit> GitLog( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
string sinceCommitId | ||
) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath == null) | ||
{ | ||
throw new ArgumentNullException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(sinceCommitId)) | ||
{ | ||
throw new ArgumentNullException(nameof(sinceCommitId)); | ||
} | ||
|
||
return context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository => | ||
{ | ||
var sinceCommit = repository.Lookup<Commit>(sinceCommitId); | ||
var refsUpToCommit = repository.Refs.ReachableFrom(new[] {sinceCommit}); | ||
return repository.Commits | ||
.QueryBy(new CommitFilter | ||
{ | ||
IncludeReachableFrom = sinceCommit, | ||
ExcludeReachableFrom = refsUpToCommit | ||
}) | ||
.Select(commit => new GitCommit(commit)) | ||
.ToList(); | ||
} | ||
); | ||
} | ||
|
||
/// <summary> | ||
/// Get up to 15 commit logs. | ||
/// </summary> | ||
/// <param name="context">The context.</param> | ||
/// <param name="repositoryDirectoryPath">Path to repository.</param> | ||
/// <param name="commitId">Commit id to lookup.</param> | ||
/// <returns>The path to the created repository.</returns> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Log")] | ||
[CakeNamespaceImport("LibGit2Sharp")] | ||
public static GitCommit GitLogLookup( | ||
this ICakeContext context, | ||
DirectoryPath repositoryDirectoryPath, | ||
string commitId | ||
) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (repositoryDirectoryPath == null) | ||
{ | ||
throw new ArgumentNullException(nameof(repositoryDirectoryPath)); | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(commitId)) | ||
{ | ||
throw new ArgumentNullException(nameof(commitId)); | ||
} | ||
|
||
return context.UseRepository( | ||
repositoryDirectoryPath, | ||
repository =>new GitCommit(repository.Lookup<Commit>(commitId)) | ||
); | ||
} | ||
} | ||
} |