Skip to content

Instantly share code, notes, and snippets.

@stronk7
Created July 26, 2016 22:54
Show Gist options
  • Save stronk7/18703ecea23a5cb57c5e9269314666f9 to your computer and use it in GitHub Desktop.
Save stronk7/18703ecea23a5cb57c5e9269314666f9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Find uses of deleted strings for a given commit within codebase.
# May lead to false positives but easily detectable in any case.
#
# Usage: within a git repo: verify_deprecated_string_uses.sh <commit>. Look for ERROR @ output or exit code.
commit=${1:-HEAD}
status=0
pushd "$(git rev-parse --show-toplevel)" > /dev/null
echo "Checking commit ${commit}"
while read -r line; do
if [[ ${line} =~ ^-\$string\[[\'\"](.*)[\"\']\]\ * ]]; then
search=${BASH_REMATCH[1]}
echo "'${search}' string removed. Looking for uses in .php files..."
# Add quotes
search="['\"]${search}['\"]"
while read -r error; do
echo " - ERROR: Use found: '${error}'"
status=1
done < <(find . -name "*.php" | xargs grep "${search}")
fi
done < <(git show ${commit})
popd > /dev/null
exit ${status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment