diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 52da066..80c7f26 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "husky": { - "version": "0.8.0", + "version": "0.9.0", "commands": [ "husky" ], diff --git a/docs/.vuepress/configs/version.ts b/docs/.vuepress/configs/version.ts index b257d05..41236e3 100644 --- a/docs/.vuepress/configs/version.ts +++ b/docs/.vuepress/configs/version.ts @@ -1 +1 @@ -export const version: string = '0.9.0' +export const version: string = '0.9.1' diff --git a/docs/guide/automate.md b/docs/guide/automate.md index d2eedad..099da89 100644 --- a/docs/guide/automate.md +++ b/docs/guide/automate.md @@ -31,7 +31,8 @@ To manually attach husky to your project, add the below code to one of your proj - + diff --git a/docs/guide/submodules.md b/docs/guide/submodules.md index 20070d4..002f095 100644 --- a/docs/guide/submodules.md +++ b/docs/guide/submodules.md @@ -34,10 +34,17 @@ The `attach` command offers a `--ignore-submodule` options that generates an MsB The generated block will look something like this, If you're attaching husky manually copy the target to your `.csproj` and adjust `WorkingDirectory` accordingly. ```xml:no-line-numbers:no-v-pre - + + + + + ``` diff --git a/src/Husky/Cli/AttachCommand.cs b/src/Husky/Cli/AttachCommand.cs index fc1f25f..09e45fa 100644 --- a/src/Husky/Cli/AttachCommand.cs +++ b/src/Husky/Cli/AttachCommand.cs @@ -83,9 +83,11 @@ private XElement GetTarget(string condition, string rootRelativePath) exec.SetAttributeValue("WorkingDirectory", rootRelativePath); target.Add(exec); + var huskyDir = Path.Combine(rootRelativePath, ".husky", "_"); var touch = new XElement("Touch"); touch.SetAttributeValue("Files", sentinelPath); touch.SetAttributeValue("AlwaysCreate", "true"); + touch.SetAttributeValue("Condition", $"Exists('{huskyDir}')"); target.Add(touch); var itemGroup = new XElement("ItemGroup"); diff --git a/src/Husky/Husky.csproj b/src/Husky/Husky.csproj index 4a1bf36..c992fcc 100644 --- a/src/Husky/Husky.csproj +++ b/src/Husky/Husky.csproj @@ -7,7 +7,7 @@ enable latest Husky - 0.9.0 + 0.9.1 Husky AliReza Sabouri Git hooks made easy, woof! @@ -68,12 +68,12 @@ - - - + + diff --git a/tests/HuskyTest/Cli/AttachCommandTests.cs b/tests/HuskyTest/Cli/AttachCommandTests.cs index 12f59a6..af66282 100644 --- a/tests/HuskyTest/Cli/AttachCommandTests.cs +++ b/tests/HuskyTest/Cli/AttachCommandTests.cs @@ -61,14 +61,16 @@ public async Task Attach_WhenParametersProvided_ShouldAddHuskyTargetElement() huskyTarget!.Descendants("Exec").Should().HaveCount(2); huskyTarget.Attribute("Inputs").Should().NotBeNull(); huskyTarget.Attribute("Outputs").Should().NotBeNull(); + + // Verify Touch is conditioned on directory existence huskyTarget.Descendants("Touch").Should().HaveCount(1); - huskyTarget.Descendants("Touch").First().Attribute("AlwaysCreate")?.Value.Should().Be("true"); + var touch = huskyTarget.Descendants("Touch").First(); + touch.Attribute("AlwaysCreate")?.Value.Should().Be("true"); + touch.Attribute("Condition")?.Value.Should().Contain("Exists("); + huskyTarget.Descendants("ItemGroup").Descendants("FileWrites").Should().HaveCount(1); _console.ReadOutputString().Trim().Should().Be("Husky dev-dependency successfully attached to this project."); - - huskyTarget.Attribute("AfterTargets")?.Value.Should().Be("Restore"); - huskyTarget.Attribute("BeforeTargets").Should().BeNull(); } [Fact]