git ls-files run from subdirectory

349 Views Asked by At

I'm trying to make a shell.sh that when run with bash will basically just run command: git ls-files -o -i --exclude-standard

which works perfectly when run from base repo directory, but when i change current directory to *repo/folder and run it from there, there is no output.

so: \
 *repo/git ls-files -o -i --exclude-standard -- good \
 *repo/folder/git ls-files -o -i --exclude-standard -- no bueno

does anyone know why it does this and how to remediate? Thanks

1

There are 1 best solutions below

0
larsks On

Running git ls-files is a little like running ls -R -- it only considers files in the current directory or below. It's producing no output because (presumably) the only files matching your criteria existing only at the top level of the repository.

It sounds like you always want to run git ls-files from the top directory, regardless of your current location. You can do that like this:

git -C $(git rev-parse --show-toplevel) ls-files -o -i --exclude-standard