Skip to content

Instantly share code, notes, and snippets.

@Antonytm
Created August 27, 2022 10:59
Show Gist options
  • Save Antonytm/1c1efdd3fb61cc31f97a3f0dac686389 to your computer and use it in GitHub Desktop.
Save Antonytm/1c1efdd3fb61cc31f97a3f0dac686389 to your computer and use it in GitHub Desktop.
Pre-commit Git hook that validates Sitecore serialization
#!/bin/sh
# Pre-commit Git hook
# It runs Sitecore CLI Serialization check
# And doesn't allow to perform commit if serialization is broken
validate=$(dotnet sitecore ser validate)
regex_errors="Errors were detected"
count=$(echo "${validate}" | grep -c "${regex_errors}")
if test $count -gt 0
then
echo "Sitecore serialization errors were detected"
echo "Please run 'dotnet sitecore ser validate'"
echo "And fix all errors before commit"
exit 1
else
exit 0
fi
@Antonytm
Copy link
Author

How to use:

  1. Download this pre-commit.sh file
  2. Put it under \.git\hooks in your repository
  3. Remove .sh extension (it needs in GitHub Gist for syntax highlighting)
  4. Enjoy pushing Sitecore serialization without mistakes 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment