Created
August 20, 2018 15:38
-
-
Save rk295/3b331af8657170c752e34f6681c56068 to your computer and use it in GitHub Desktop.
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 | |
# | |
# Sample script which outputs the list of root level directories containing | |
# modified files in the last commit | |
# | |
set -euo pipefail | |
IFS=$'\n\t' | |
changedDirs=() | |
find_in_array() { | |
local word array | |
word="${1:-}" | |
array="${2-}" | |
for e in "${array[@]}"; do [[ "$e" == "$word" ]] && return 0 || return 1; done | |
} | |
while read -r file ; do | |
baseDir="${file%%/*}" | |
find_in_array "$baseDir" "${changedDirs[@]}" || changedDirs+=("$baseDir") | |
done < <(git diff-tree --no-commit-id --name-only -r HEAD^) | |
echo "Changed Dirs = ${changedDirs[*]}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment