Skip to content

Instantly share code, notes, and snippets.

@eric-khoury
Created June 16, 2021 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eric-khoury/0b2f6568287aac6b9e5b6b73147ccfa6 to your computer and use it in GitHub Desktop.
Save eric-khoury/0b2f6568287aac6b9e5b6b73147ccfa6 to your computer and use it in GitHub Desktop.
script used as a git pre-commit script to see if any data-testid has changed in the DOM in the commit
#!/bin/bash
RED='\033[1;31m'
YELLOW='\033[0;33m'
END_COLOR='\e[0m'
currentCommit=$(git show -s --format=%H)
numOfLinesChangedWithTestIds=$(git diff $currentCommit~ $currentCommit -G testid --stat | wc -l)
filesChanged=$(git diff $currentCommit~ $currentCommit -G testid --name-only ':(exclude)changedTestIds.sh')
if (( $numOfLinesChangedWithTestIds > 0 ));
then
printf "${RED}\n\n\n🔥🔥🔥🚨-----> YOU HAVE CHANGED A TEST ID <-----🚨🔥🔥🔥\n\n${END_COLOR}"
printf "${YELLOW}-> ${filesChanged}${END_COLOR}\n\n\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment