Skip to content

Add one-time installation of a pre-commit git hook to protect generated WPF files #1075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 24, 2019
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
56 changes: 56 additions & 0 deletions eng/WpfArcadeSdk/tools/InlineTasks.targets
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,60 @@
</Code>
</Task>
</UsingTask>

<!-- Installs WPF pre-commit git hook to protect generated files -->
<Target Name="InstallWPFPreCommitGitHook">
<Message Text="InstallWPFPreCommitGitHook: WPF repo root: $(RepoRoot)" />
<Message Text="InstallWPFPreCommitGitHook: WPF Arcade SDK tools root: $(WpfArcadeSdkToolsDir)" />
<InstallWPFPreCommitGitHook RepoRoot="$(RepoRoot)" WpfArcadeSdkToolsDir="$(WpfArcadeSdkToolsDir)" />
</Target>

<UsingTask TaskName="InstallWPFPreCommitGitHook"
TaskFactory="$(TaskFactoryToUse)"
AssemblyFile="$(TaskFactoryAssemblyToUse)">
<ParameterGroup>
<RepoRoot ParameterType="System.String" Required="true" />
<WpfArcadeSdkToolsDir ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Code Type="Fragment" Language="cs">
<![CDATA[
string WPFPreCommitGitHookSource = Path.Combine(WpfArcadeSdkToolsDir, @"pre-commit.githook");
string WPFPreCommitGitHookDest = Path.Combine(RepoRoot, @".git\hooks\pre-commit");
Log.LogMessage($"InstallWPFPreCommitGitHook: WPFPreCommitGitHookSource: {WPFPreCommitGitHookSource}");
Log.LogMessage($"InstallWPFPreCommitGitHook: WPFPreCommitGitHookDest: {WPFPreCommitGitHookDest}");

try
{
Log.LogMessage("InstallWPFPreCommitGitHook: Detecting pre-comit git hook...");

// Verify the payload file exists
if (!File.Exists(WPFPreCommitGitHookSource))
{
throw new Exception($"InstallWPFPreCommitGitHook: {WPFPreCommitGitHookSource} file does not exit.");
}

// Install pre-commit hook if it has not been installed
if (!File.Exists(WPFPreCommitGitHookDest))
{
Log.LogMessage("InstallWPFPreCommitGitHook: Installing pre-comit git hook...");
File.Copy(WPFPreCommitGitHookSource, WPFPreCommitGitHookDest);
}
else
{
Log.LogMessage("InstallWPFPreCommitGitHook: pre-comit git hook already installed.");
}
}
catch (Exception e)
{
Log.LogErrorFromException(e);
throw e;
}
]]>
</Code>
</Task>
</UsingTask>

</Project>
Loading