0

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

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
zecmirit
  • 1
  • 1
  • `git ls-files` only lists the files tracked by git. Are you in a `folder` that is ignored (`.gitignore`), contains only ignored files, or does not contain any files at all? Note that `--exclude-standard` still won't cause it to include untracked files. – Thomas Feb 03 '22 at 12:26
  • .gitignore is in the repo folder, but i need to run it from repo/folder – zecmirit Feb 03 '22 at 12:28

1 Answers1

2

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
larsks
  • 277,717
  • 41
  • 399
  • 399