Skip to content

Instantly share code, notes, and snippets.

@Antonytm
Created August 27, 2022 10:59
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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