Created
December 9, 2019 19:42
-
-
Save sanusart/9e6e784d0773e3c2977549dbcf86112e to your computer and use it in GitHub Desktop.
Git match changes in commit #bash #shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
# Usage: | |
# | |
# bash ./scripts/git-files COMMIT_HASH | |
# | |
# Usage in script: | |
# | |
# if [ $(bash ./scripts/git-files-changes "${COMMIT_HASH}") -eq 0 ]; | |
# then exit 0; | |
# fi | |
# Commit hash of commit to check | |
COMMIT_HASH=$1; | |
# Matches array | |
MATCHES=( | |
"^comp(.*)\.(tsx|js|less)$" | |
"^webpack(.*)\.js" | |
); | |
# Joins array of matches by pipe "|" char | |
PATTERN=$(echo "${MATCHES[@]}" | tr ' ' '|') | |
# returns match line count, 0 for no matches or N for number of mathed lines | |
git diff-tree --no-commit-id --name-only -r "${COMMIT_HASH}" | grep -c -E "$PATTERN" | xargs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment