Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/guide/automate.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ To manually attach husky to your project, add the below code to one of your proj
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High"/>
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High"
WorkingDirectory="../../" /> <!--Update this to the relative path to your project root dir -->
<Touch Files="../../.husky/_/install.stamp" AlwaysCreate="true" />
<Touch Files="../../.husky/_/install.stamp" AlwaysCreate="true"
Condition="Exists('../../.husky/_')" />
<ItemGroup>
<FileWrites Include="../../.husky/_/install.stamp" />
</ItemGroup>
Expand Down
9 changes: 8 additions & 1 deletion docs/guide/submodules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<Target Name="husky" AfterTargets="Restore" Condition="'$(HUSKY)' != 0 and '$(IgnoreSubmodule)' != 0">
<Target Name="husky" AfterTargets="Restore" Condition="'$(HUSKY)' != 0 and '$(IgnoreSubmodule)' != 0"
Inputs="../../.config/dotnet-tools.json"
Outputs="../../.husky/_/install.stamp">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High"/>
<Exec Command="dotnet husky install --ignore-submodule" StandardOutputImportance="Low" StandardErrorImportance="High"
WorkingDirectory="../../" /> <!--Update this to the relative path to your project root dir -->
<Touch Files="../../.husky/_/install.stamp" AlwaysCreate="true"
Condition="Exists('../../.husky/_')" />
<ItemGroup>
<FileWrites Include="../../.husky/_/install.stamp" />
</ItemGroup>
</Target>
```

Expand Down
2 changes: 2 additions & 0 deletions src/Husky/Cli/AttachCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/Husky/Husky.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
<Compile Remove="Utils\Dotnet\ParallelETWProvider.cs" />
<Compile Remove="Utils\Dotnet\Parallel.cs" />
</ItemGroup>
<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0 and '$(IsCrossTargetingBuild)' == 'true'"
<Target Name="Husky" AfterTargets="Restore" Condition="'$(HUSKY)' != 0 and '$(IsCrossTargetingBuild)' == 'true'"
Inputs="../../.config/dotnet-tools.json"
Outputs="../../.husky/_/install.stamp">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory="..\.." />
<Touch Files="../../.husky/_/install.stamp" AlwaysCreate="true" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory="../../"/>
<Touch Files="../../.husky/_/install.stamp" AlwaysCreate="true" Condition="Exists('../../.husky/_')" />
<ItemGroup>
<FileWrites Include="../../.husky/_/install.stamp" />
</ItemGroup>
Expand Down
10 changes: 6 additions & 4 deletions tests/HuskyTest/Cli/AttachCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down