git ls-files -X option is relative to repo root
- From
- Daniel Finnie <dan@danfinnie.com>
- Date
- Feb 13, 2015, 19:23 UTC
- Message-ID
- <CAG4vEKM-2sy0z3=YLS+rgH99w6ukdcNBode9CAh4C4t9eSa02A@mail.gmail.com>
I encountered some unexpected behavior with Git today and was hoping to either a) clear up my misconception or b) make a bug report.
My question deals with the --exclude-from option to git-ls-files. It appears that paths passed to this option are relative to the root of the repository, not your current working directory. I would have expected the opposite, that the paths are relative to the working directory. I would expect to put a colon at the beginning of the path to make it relative to the repository root. Here's an example:
$ tree -a -I .git
.
├── .gitignore
└── example_dir
├── .gitignore
└── example_file# (all of these files are checked in, including example_file which is also in .gitignore)
$ cat .gitignore # empty gitignore
$ cat example_dir/.gitignore example_file
$ (cd example_dir && git ls-files --ignore --exclude-from=.gitignore) # No output because this references the git ignore at the project root, not example_dir. I expected this to output "example_file".
$ (cd example_dir && git ls-files --ignore --exclude-from=example_dir/.gitignore) example_file # works for the reason above, but I expected this to break because example_dir/example_dir/.gitignore is not a file
So, what do you think? Am I missing a git/*nix convention explaining options would be specified relative to the repository root? Or is this a git bug?
Thanks for your time, Dan Finnie