Skip to content

Instantly share code, notes, and snippets.

@sanusart
Created December 9, 2019 19:42
Show Gist options
  • Save sanusart/9e6e784d0773e3c2977549dbcf86112e to your computer and use it in GitHub Desktop.
Save sanusart/9e6e784d0773e3c2977549dbcf86112e to your computer and use it in GitHub Desktop.
Git match changes in commit #bash #shell
#!/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