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
4 changes: 2 additions & 2 deletions docs/guide/automate.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ You can set the `HUSKY` environment variable to `0` in order to disable husky in
To manually attach husky to your project, add the below code to one of your projects (*.csproj/*.vbproj).

``` xml:no-line-numbers:no-v-pre
<Target Name="husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0"
<Target Name="husky" AfterTargets="Restore" Condition="'$(HUSKY)' != 0"
Inputs="../../.config/dotnet-tools.json"
Outputs="../../.husky/_/install.stamp">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High"/>
Expand Down Expand Up @@ -59,7 +59,7 @@ to avoid this, you can add the `$(IsCrossTargetingBuild)' == 'true'` condition t
e.g

``` xml:no-line-numbers:no-v-pre
<Target Name="husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0 and '$(IsCrossTargetingBuild)' == 'true'">
<Target Name="husky" AfterTargets="Restore" Condition="'$(HUSKY)' != 0 and '$(IsCrossTargetingBuild)' == 'true'">
...
```

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/submodules.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ 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" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0 and '$(IgnoreSubmodule)' != 0">
<Target Name="husky" AfterTargets="Restore" Condition="'$(HUSKY)' != 0 and '$(IgnoreSubmodule)' != 0">
<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 -->
Expand Down
2 changes: 1 addition & 1 deletion src/Husky/Cli/AttachCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private XElement GetTarget(string condition, string rootRelativePath)

var target = new XElement("Target");
target.SetAttributeValue("Name", "Husky");
target.SetAttributeValue("BeforeTargets", "Restore;CollectPackageReferences");
target.SetAttributeValue("AfterTargets", "Restore");
target.SetAttributeValue("Condition", condition);
target.SetAttributeValue("Inputs", inputPath);
target.SetAttributeValue("Outputs", sentinelPath);
Expand Down
3 changes: 3 additions & 0 deletions tests/HuskyTest/Cli/AttachCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
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 Expand Up @@ -145,7 +148,7 @@
.SingleOrDefault(q => q.Attribute("Name")?.Value == "Husky")?.Descendants("Exec");

targetExecElements.Should().NotBeNull().And.HaveCount(2);
targetExecElements.SingleOrDefault(e => e.Attribute("Command").Value.Contains("dotnet husky install --ignore-submodule")).Should().NotBeNull();

Check warning on line 151 in tests/HuskyTest/Cli/AttachCommandTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 151 in tests/HuskyTest/Cli/AttachCommandTests.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'XElement? Enumerable.SingleOrDefault<XElement>(IEnumerable<XElement> source, Func<XElement, bool> predicate)'.

Check warning on line 151 in tests/HuskyTest/Cli/AttachCommandTests.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 151 in tests/HuskyTest/Cli/AttachCommandTests.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'XElement? Enumerable.SingleOrDefault<XElement>(IEnumerable<XElement> source, Func<XElement, bool> predicate)'.
_xmlIo.Received(1).Save(Arg.Any<string>(), Arg.Any<XElement>());
}

Expand Down
Loading