Add one-time installation of a pre-commit git hook to protect generated WPF files #1075
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change adds a one-time installation of a pre-commit git hook to protect all of WPF's generated files. Attempts to commit changes to these files will be blocked (along with an error message).
There are two cases based on the location of
Microsoft.DotNet.Arcade.Wpf.Sdk
:Microsoft.DotNet.Arcade.Wpf.Sdk
is present in the local Git repo (e.g., dotnet-wpf/eng/wpfarcadesdk).Microsoft.DotNet.Arcade.Wpf.Sdk
is in the NuGet cache (%userprofile%\.nuget\packages\microsoft.dotnet.arcade.wpf.sdk). In this case, the path to the WPF Arcade SDK is resolved at build time based on the SDK version inglobal.json
.For case 1, a simple poweshell script is used to install the git hook. For case 2, an inline task is called to get the tools path and install the git hook. The task consumes a property set by
Sdk.props
, imported by the Wpf Arcade SDK, which determines theMicrosoft.DotNet.Arcade.Wpf.Sdk
path at build time.The script checks for the existence of eng/WpfArcadeSdk and/or an entry for the SDK in
global.json
to determine case #1 or #2.Again, note that the build file Sdk.props needs to be imported for
WpfArcadeSdkToolsDir
to be set (i.e., the parameter is only available in a WPF Arcade SDK project at build time.)