summaryrefslogtreecommitdiff
path: root/share/spack/qa/changed_files
blob: 9c60b3b20b2803a5a721460c74d8192de4f767e5 (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 --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