From 3fe180f1ddc15543e9486dca5fb1d25424918d55 Mon Sep 17 00:00:00 2001 From: Kevin DeLorey Date: Wed, 5 May 2021 16:09:13 -0600 Subject: [PATCH 1/8] Initial commit of the get config method. --- src/Cake.Git/GitAliases.Config.cs | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/Cake.Git/GitAliases.Config.cs diff --git a/src/Cake.Git/GitAliases.Config.cs b/src/Cake.Git/GitAliases.Config.cs new file mode 100644 index 0000000..4407f01 --- /dev/null +++ b/src/Cake.Git/GitAliases.Config.cs @@ -0,0 +1,47 @@ +using System; +using Cake.Core; +using Cake.Core.Annotations; +using Cake.Core.IO; +using Cake.Git.Extensions; + +namespace Cake.Git +{ + public static partial class GitAliases + { + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Configuration")] + public static T GitConfigGet( + this ICakeContext context, + DirectoryPath repositoryDirectoryPath, + string key) + { + if (context is null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (repositoryDirectoryPath is null) + { + throw new ArgumentException(nameof(repositoryDirectoryPath)); + } + + return context.UseRepository( + repositoryDirectoryPath, + repository => repository.Config.Get(key).Value); + } + } +} \ No newline at end of file From 4d9563022dc45f94191ac11334eba31ccba4c279 Mon Sep 17 00:00:00 2001 From: Kevin DeLorey Date: Sat, 8 May 2021 10:02:32 -0600 Subject: [PATCH 2/8] Added more basic configuration methods. --- src/Cake.Git/GitAliases.Config.cs | 192 ++++++++++++++++++++++++++++-- 1 file changed, 185 insertions(+), 7 deletions(-) diff --git a/src/Cake.Git/GitAliases.Config.cs b/src/Cake.Git/GitAliases.Config.cs index 4407f01..2d8a260 100644 --- a/src/Cake.Git/GitAliases.Config.cs +++ b/src/Cake.Git/GitAliases.Config.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Cake.Core; using Cake.Core.Annotations; using Cake.Core.IO; @@ -9,19 +10,26 @@ namespace Cake.Git public static partial class GitAliases { /// - /// + /// Gets the specified configuration value. /// /// - /// - /// - /// + /// + /// + /// var configValue = GitConfigGet<string>("user.email"); + /// + /// + /// + /// The context. + /// Repository path. + /// The configuration key. /// - /// + /// The expected type of configuration. /// - /// + /// The value of the specified configuration key. /// /// /// + /// Configuration value not found. [CakeMethodAlias] [CakeAliasCategory("Configuration")] public static T GitConfigGet( @@ -41,7 +49,177 @@ public static T GitConfigGet( return context.UseRepository( repositoryDirectoryPath, - repository => repository.Config.Get(key).Value); + repository => + { + var config = repository.Config.Get(key) + ?? throw new KeyNotFoundException("Configuration not found."); + + return config.Value; + }); + } + + /// + /// Gets the specified configuration value. If the specified value is not found it will return the specified + /// default value. + /// + /// + /// + /// + /// var configValue = GitConfigGet("user.email", "bob@example.com"); + /// + /// + /// + /// The context. + /// Repository path. + /// The configuration key. + /// The default value to use if the configuration isn't present. + /// + /// The expected type of configuration. + /// + /// The value of the specified configuration key. + /// + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Configuration")] + public static T GitConfigGet( + this ICakeContext context, + DirectoryPath repositoryDirectoryPath, + string key, + T defaultValue) + { + if (context is null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (repositoryDirectoryPath is null) + { + throw new ArgumentException(nameof(repositoryDirectoryPath)); + } + + return context.UseRepository( + repositoryDirectoryPath, + repository => repository.Config.GetValueOrDefault(key)); + } + + /// + /// Gets the specified configuration value. If the specified value is not found it will return the specified + /// default value. + /// + /// + /// + /// + /// GitConfigSet("user.email", "bob@example.com"); + /// + /// + /// + /// The context. + /// Repository path. + /// The configuration key. + /// The new value. + /// + /// The type of configuration. + /// + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Configuration")] + public static void GitConfigSet( + this ICakeContext context, + DirectoryPath repositoryDirectoryPath, + string key, + T newValue) + { + if (context is null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (repositoryDirectoryPath is null) + { + throw new ArgumentException(nameof(repositoryDirectoryPath)); + } + + context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Set(key, newValue)); + } + + /// + /// Unsets the specified local configuration key. + /// + /// + /// + /// + /// GitConfigUnsetLocal("user.email", "bob@example.com"); + /// + /// + /// + /// The context. + /// Repository path. + /// The configuration key. + /// + /// Whether the key was unset. + /// + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Configuration")] + public static void GitConfigUnsetLocal( + this ICakeContext context, + DirectoryPath repositoryDirectoryPath, + string key) + { + if (context is null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (repositoryDirectoryPath is null) + { + throw new ArgumentException(nameof(repositoryDirectoryPath)); + } + + context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Unset(key)); + } + + /// + /// Returns whether a configuration value exists with the specifed key. + /// + /// + /// + /// + /// if (GetConfigurationExists<string>("user.email") + /// { + /// //.. + /// } + /// + /// + /// + /// The context. + /// Repository path. + /// The configuration key. + /// + /// The expected configuration type. + /// + /// Whether a configuration exists with the specified key. + /// + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Configuration")] + public static bool GitConfigExist(this ICakeContext context, DirectoryPath repositoryDirectoryPath, string key) + { + if (context is null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (repositoryDirectoryPath is null) + { + throw new ArgumentException(nameof(repositoryDirectoryPath)); + } + + return context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Get(key) != null); } } } \ No newline at end of file From 87b32f2a078a387bb60e0b1b653e214ab799e5e6 Mon Sep 17 00:00:00 2001 From: Kevin DeLorey Date: Sat, 8 May 2021 10:31:00 -0600 Subject: [PATCH 3/8] Added some tests. --- src/Cake.Git/GitAliases.Config.cs | 7 ++++--- test.cake | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Cake.Git/GitAliases.Config.cs b/src/Cake.Git/GitAliases.Config.cs index 2d8a260..1f17193 100644 --- a/src/Cake.Git/GitAliases.Config.cs +++ b/src/Cake.Git/GitAliases.Config.cs @@ -4,6 +4,7 @@ using Cake.Core.Annotations; using Cake.Core.IO; using Cake.Git.Extensions; +using LibGit2Sharp; namespace Cake.Git { @@ -125,7 +126,7 @@ public static T GitConfigGet( /// [CakeMethodAlias] [CakeAliasCategory("Configuration")] - public static void GitConfigSet( + public static void GitConfigSetLocal( this ICakeContext context, DirectoryPath repositoryDirectoryPath, string key, @@ -141,7 +142,7 @@ public static void GitConfigSet( throw new ArgumentException(nameof(repositoryDirectoryPath)); } - context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Set(key, newValue)); + context.UseRepository(repositoryDirectoryPath, repository => repository.Config.Set(key, newValue, ConfigurationLevel.Local)); } /// @@ -207,7 +208,7 @@ public static void GitConfigUnsetLocal( /// [CakeMethodAlias] [CakeAliasCategory("Configuration")] - public static bool GitConfigExist(this ICakeContext context, DirectoryPath repositoryDirectoryPath, string key) + public static bool GitConfigExists(this ICakeContext context, DirectoryPath repositoryDirectoryPath, string key) { if (context is null) { diff --git a/test.cake b/test.cake index 273b529..3373d22 100644 --- a/test.cake +++ b/test.cake @@ -839,6 +839,22 @@ Task("Git-Log-Tag") } }); +Task("Git-Config") + .Does(() => +{ + GitConfigSetLocal(testInitalRepo, "user.email", "bob@example.com"); + + if (GitConfigExists(testInitalRepo, "user.email")) + { + string email = GitConfigGet(testInitalRepo, "user.email"); + + if (!string.Equals("bob@example.com", email)) + { + throw new InvalidOperationException("Wrong email in configuration."); + } + } +}); + Task("Git-Tag") @@ -924,7 +940,8 @@ Task("Default-Tests") .IsDependentOn("Git-AllTags") .IsDependentOn("Git-AllTags-Annotated") .IsDependentOn("Git-AllTags-Targets") - .IsDependentOn("Git-Clean"); + .IsDependentOn("Git-Clean") + .IsDependentOn("Git-Config"); Task("Local-Tests") .IsDependentOn("Git-Init") @@ -960,7 +977,8 @@ Task("Local-Tests") .IsDependentOn("Git-AllTags") .IsDependentOn("Git-AllTags-Annotated") .IsDependentOn("Git-AllTags-Targets") - .IsDependentOn("Git-Clean"); + .IsDependentOn("Git-Clean") + .IsDependentOn("Git-Config"); /////////////////////////////////////////////////////////////////////////////// // EXECUTION From e9a757f45e5740b36ea47f8754aee97944b415e9 Mon Sep 17 00:00:00 2001 From: "C. Augusto Proiete" Date: Wed, 4 Aug 2021 00:19:40 -0300 Subject: [PATCH 4/8] Update to LibGit2Sharp v0.27.0-preview-0102 --- src/Cake.Git/Cake.Git.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Git/Cake.Git.csproj b/src/Cake.Git/Cake.Git.csproj index 9e4c96e..acad521 100644 --- a/src/Cake.Git/Cake.Git.csproj +++ b/src/Cake.Git/Cake.Git.csproj @@ -22,7 +22,7 @@ - + From 199a7c92908290cfeaa0589a29ba0df0bdbd3714 Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Mon, 9 Aug 2021 10:10:54 +0200 Subject: [PATCH 5/8] Add GitHub actions --- .github/workflows/build.yml | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..ac7b777 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,46 @@ +name: Build +on: + pull_request: + push: + branches: + - master + - develop + - hotfix/* + +jobs: + build: + name: Build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + steps: + - name: Get the sources + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Install .NET Core SDK 3.1.x + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '3.1.x' + + - name: Install .NET Core SDK + uses: actions/setup-dotnet@v1 + + - if: matrix.os == 'windows-latest' + name: Run Cake script Windows + run: | + ./build.ps1 + + - if: matrix.os != 'windows-latest' + name: Run Cake script Posix + run: | + ./build.sh + + - name: Upload Artifacts + uses: actions/upload-artifact@v2 + with: + name: artifacts + path: artifacts \ No newline at end of file From 0a4468e040cb25a6eb744355761b3ce859125572 Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Mon, 9 Aug 2021 10:16:06 +0200 Subject: [PATCH 6/8] Test ubuntu-18.04 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ac7b777..3e58338 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - os: [windows-latest, ubuntu-latest, macos-latest] + os: [ubuntu-18.04, ubuntu-latest, macos-latest] steps: - name: Get the sources uses: actions/checkout@v2 From 9e20e09863787cce756a304f9211acb715206850 Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Mon, 9 Aug 2021 11:13:17 +0200 Subject: [PATCH 7/8] Use preview LibGit2Sharp for all monikers --- build.cake | 6 ++++++ src/Cake.Git/Cake.Git.csproj | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/build.cake b/build.cake index cfb1a05..6c6fd6b 100644 --- a/build.cake +++ b/build.cake @@ -78,6 +78,12 @@ if (!isLocalBuild) AppVeyor.UpdateBuildVersion(semVersion); } +if (BuildSystem.GitHubActions.IsRunningOnGitHubActions) +{ + TaskSetup(context=> System.Console.WriteLine($"::group::{context.Task.Name.Quote()}")); + TaskTeardown(context=>System.Console.WriteLine("::endgroup::")); +} + /////////////////////////////////////////////////////////////////////////////// // SETUP / TEARDOWN /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Cake.Git/Cake.Git.csproj b/src/Cake.Git/Cake.Git.csproj index acad521..e5a3f9f 100644 --- a/src/Cake.Git/Cake.Git.csproj +++ b/src/Cake.Git/Cake.Git.csproj @@ -20,13 +20,12 @@ - - - + + From 1f5e96c5cb44688b568e7b7f949c8ad4ef609cc9 Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Mon, 9 Aug 2021 11:49:38 +0200 Subject: [PATCH 8/8] Update 1.1.0 release notes --- .github/workflows/build.yml | 8 +++++++- ReleaseNotes.md | 9 ++++++++- src/SolutionInfo.cs | 6 +++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3e58338..91d68ac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,4 +43,10 @@ jobs: uses: actions/upload-artifact@v2 with: name: artifacts - path: artifacts \ No newline at end of file + path: artifacts + + - name: Upload NuGet Package + uses: actions/upload-artifact@v2 + with: + name: nuget + path: nuget \ No newline at end of file diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 0c2df43..f25985f 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,10 +1,17 @@ +### New in 1.1.0 (Released 2021/08/09) + +* Update LibGit2Sharp to 0.27.0-preview-0102 +* Add Basic Support for git Configuration Commands + ### New in 1.0.1 (Released 2021/03/12) * Add cake-addin tag to NuGet package ### New in 1.0.0 (Released 2021/02/09) -* Bumped Cake.Core to 1.0.0 +* Update Cake.Git to target Cake v1.0.0 +* Issue with accessing Tag properties +* Exception TargetInvocationException in GitTags(..) ### New in 0.22.0 (Released 2020/06/26) diff --git a/src/SolutionInfo.cs b/src/SolutionInfo.cs index b1310f7..c96552c 100644 --- a/src/SolutionInfo.cs +++ b/src/SolutionInfo.cs @@ -10,9 +10,9 @@ [assembly: AssemblyDescription("Cake Git AddIn")] [assembly: AssemblyCompany("WCOM AB")] [assembly: AssemblyProduct("Cake.Git")] -[assembly: AssemblyVersion("1.0.1")] -[assembly: AssemblyFileVersion("1.0.1")] -[assembly: AssemblyInformationalVersion("1.0.1")] +[assembly: AssemblyVersion("1.1.0")] +[assembly: AssemblyFileVersion("1.1.0")] +[assembly: AssemblyInformationalVersion("1.1.0")] [assembly: AssemblyCopyright("Copyright © WCOM AB 2021")] [assembly: CLSCompliant(true)]