git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git ls-files -X option is relative to repo root

From
DFDaniel Finnie <dan@danfinnie.com>
Date
Feb 13, 2015, 21:19 UTC
Message-ID
<CAG4vEKP760_sq1fsJD_1jjz0_G+T8NosSXDqx0bvQy4tPVz5JQ@mail.gmail.com>
In-Reply-To
<xmqqiof5mt0q.fsf@gitster.dls.corp.google.com>
Hi Junio,

Thanks for the info and backstory. I didn't realize that the paths in the file specified by --exclude-from would be relative to the project root. That makes my original use case kind of silly (it's a long story, but I was curious which files were ignored by a subset of my .gitignore files). This makes the example I gave before wrong in that the contents of example_dir/.gitignore should have been relative to the project root.

There are 2 sets of paths that can be relative to the working
directory or the project root with --exclude-from:
* The path to the file containing exclusion rules
* The paths of the exclusion rules themselves (the contents of the
file from the previous bullet point)

I now see why the second needs to be relative to the project root. I still think it's more intuitive for the first (the path to the file containing exclusions) to be relative to the current directory. Your example of `git ls-files -X /var/tmp/exclude -i` uses an absolute path, let's look at one with a relative path. Say you wanted to check what files were being ignored from your .git/info/exclude file from a subdirectory of your project. I would expect to run `cd subdirectory && git ls-files --ignore --other --exclude-from=../.git/info/exclude`. The correct command, though, is `cd subdirectory && git ls-files --ignore --other --exclude-from=.git/info/exclude`, even though I'm in a subdirectory.

Do you have any comments on why the path in --exclude-from=<path> is relative to the project root?

Thanks, Dan

On Fri, Feb 13, 2015 at 3:54 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 23 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> ...  It does not make sense to allow where you are
>> to affect behaviour of the command, i.e. in these two invocations of
>> ls-files:
>>
>>       git ls-files -X /var/tmp/exclude -i
>>         cd example && git ls-files -X /var/tmp/exclude -i
>>
>> if the same line in /var/tmp/exclude meant completely different
>> things, it would be crazy.
>
> To put it another way, think of --exclude-from as a way to specify a
> replacement for .git/info/excludes, and --exclude-per-directory as a
> way to specify a replacement for the in-tree .gitignore files.
>
> Historically, we did not have the --exclude-standard option from the
> beginning, and only after we gained experience with --exclude-from
> and --exclude-per-directory in our scripts, the --exclude-standard
> was added to codify the (then-) best-current-practice after the fact,
> and we used --exclude-from for exactly that purpose before then.
>
> cf. 8e7b07c8 (git-ls-files: add --exclude-standard, 2007-11-15)
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 5 in “git ls-files -X option is relative to repo root”
  1. Daniel FinnieFeb 13, 2015
  2. Junio C HamanoFeb 13, 2015
  3. Junio C HamanoFeb 13, 2015
  4. Daniel FinnieFeb 13, 2015
  5. Junio C HamanoFeb 13, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.