Skip to content

Instantly share code, notes, and snippets.

@rk295
Created August 20, 2018 15:38
Show Gist options
  • Save rk295/3b331af8657170c752e34f6681c56068 to your computer and use it in GitHub Desktop.
Save rk295/3b331af8657170c752e34f6681c56068 to your computer and use it in GitHub Desktop.
#!/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