spack/share/spack/qa/changed_files
2016-08-30 15:21:15 -05:00

32 lines
981 B
Bash
Executable File

#!/usr/bin/env bash
#
# Description:
# Returns a list of changed files.
#
# Usage:
# changed_files [<directory> ...]
# changed_files [<file> ...]
# changed_files ["*.<extension>" ...]
#
# Options:
# Directories, files, or globs to search for changed files.
#
# Move to root directory of Spack
# Allows script to be run from anywhere
SPACK_ROOT="$(dirname "$0")/../../.."
cd "$SPACK_ROOT"
# Add changed files that have been committed since branching off of develop
changed=($(git diff --name-only --find-renames develop... -- "$@"))
# Add changed files that have been staged but not yet committed
changed+=($(git diff --name-only --find-renames --cached -- "$@"))
# Add changed files that are unstaged
changed+=($(git diff --name-only --find-renames -- "$@"))
# Add new files that are untracked
changed+=($(git ls-files --exclude-standard --other -- "$@"))
# Return array
# Ensure that each file in the array is unique
printf '%s\n' "${changed[@]}" | sort -u