I am trying to use git ls-files with file patterns to get a filtered list of tracked files. (I know I could do the below with grep et. al but I am curious why it doesn't work)
#!/usr/bin/env bash
GIT_ROOT=$(git rev-parse --show-toplevel)
# only include stuff in src and include
SRC_PATTERNS="{include,src}/**/*.{hpp,cpp,tpp,h,c}"
# @brief Get list of files in git index with names relative to root
# @param $1 Any of the constraints git-ls-files knows (e.g. --cached)
function git_sources()
{
FILE_STRING=$(git -C $GIT_ROOT ls-files --full-name $1 $SRC_PATTERNS)
echo "$FILE_STRING"
}
The glob I am using works when invoking the git ls-files command from the command line
git -C $GIT_ROOT ls-files --full-name --cached {include,src}/**/*.{hpp,cpp,tpp,h,c}
But not when invoking the git_sources command after sourcing the script.
Question: How do I properly quote the glob pattern so it is passed to the subcommand as if invoked directly from the command line?