summaryrefslogtreecommitdiff
path: root/share/spack/qa/changed_files
blob: c1fa55c053f7b5b272e331daa7c68f9213a036a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/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 --diff-filter=ACMR develop... -- "$@"))
# Add changed files that have been staged but not yet committed
changed+=($(git diff --name-only --diff-filter=ACMR --cached -- "$@"))
# Add changed files that are unstaged
changed+=($(git diff --name-only --diff-filter=ACMR -- "$@"))
# 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