mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-09 13:43:46 -05:00
improve stop words check
This commit is contained in:
@@ -17,7 +17,7 @@ _mainScript_() {
|
|||||||
STOP_WORD_FILE="${HOME}/.git_stop_words"
|
STOP_WORD_FILE="${HOME}/.git_stop_words"
|
||||||
GIT_DIFF_TEMP="${TMP_DIR}/diff.txt"
|
GIT_DIFF_TEMP="${TMP_DIR}/diff.txt"
|
||||||
|
|
||||||
if [ -f "${STOP_WORD_FILE}" ]; then
|
if cat "${STOP_WORD_FILE}" | grep . | grep -v '# ' >"${TMP_DIR}/pattern_file.txt"; then
|
||||||
|
|
||||||
if [[ $(basename "${STOP_WORD_FILE}") == "$(basename "${1}")" ]]; then
|
if [[ $(basename "${STOP_WORD_FILE}") == "$(basename "${1}")" ]]; then
|
||||||
debug "Don't check stop words file for stop words. Skipping $(basename "${1}")"
|
debug "Don't check stop words file for stop words. Skipping $(basename "${1}")"
|
||||||
@@ -25,18 +25,16 @@ _mainScript_() {
|
|||||||
fi
|
fi
|
||||||
debug "Checking for stop words"
|
debug "Checking for stop words"
|
||||||
|
|
||||||
# remove blank lines from stopwords file
|
# remove blank lines and comments from stopwords file
|
||||||
cat "${STOP_WORD_FILE}" | sed '/^$/d' > "${TMP_DIR}/pattern_file.txt"
|
|
||||||
|
|
||||||
# Add diff to a temporary file
|
# Add diff to a temporary file
|
||||||
git diff --cached -- "${1}" | grep '^+' >"${GIT_DIFF_TEMP}"
|
git diff --cached -- "${1}" | grep '^+' >"${GIT_DIFF_TEMP}"
|
||||||
|
|
||||||
if grep --file="${TMP_DIR}/pattern_file.txt" "${GIT_DIFF_TEMP}"; then
|
if grep --file="${TMP_DIR}/pattern_file.txt" "${GIT_DIFF_TEMP}"; then
|
||||||
error "Found git stop word in '$(basename "${1}")'"
|
error "Found git stop word in '$(basename "${1}")'"
|
||||||
_safeExit_ 1
|
_safeExit_ 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
debug "Could not find git stopwords file expected at '${STOP_WORD_FILE}'. Continuing..."
|
debug "Could not find git stopwords file expected at '${STOP_WORD_FILE}'. Or it was empty. Continuing..."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user