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

Expected behaviour for pathspecs matching attributes in subdirectories

From
MHMatthew Hughes <mhughes@uw.co.uk>
Date
Jul 6, 2023, 10:33 UTC
Message-ID
<CAEzX-aD1wfgp8AvNNfCXVM3jAaAjK+uFTqS2XP4CJbVvFr2BtQ@mail.gmail.com>
Hi,
I'm working with pathspecs matching on attributes, here's a basic repo setup:
    $ git init .
    $ mkdir -p sub/sub
    $ touch fileA sub/fileA sub/sub/fileA
    $ echo 'fileA labelA' > sub/.gitattributes
    $ git add .
    $ git commit -m 'Build the repo'

What I want to do: list all files under 'sub/sub' that have 'labelA' as an attribute.

Working from the top level I get the output I would expect:
    $ git ls-files -- ':(attr:labelA)'
    sub/fileA
    sub/sub/fileA
    $ git ls-files -- ':(attr:labelA)sub'
    sub/fileA
    sub/sub/fileA

But as soon as a directory is included in the pathspec's path no files are returned:

    $ git ls-files -- ':(attr:labelA)sub/'
    $ git ls-files -- ':(attr:labelA)sub/sub'
Without the attribtue magic I can use a directory to list files there:
    $ git ls-files -- sub/sub
    sub/sub/fileA

Is this the expected behaviour? I looked in t/t6135-pathspec-with-attrs.sh and didn't see a test case covering something similar. If this is expected, is there another way to achieve what I'm looking for?

Thanks for your time, Matt

Next: Junio C Hamano
Message 1 of 9 in “Expected behaviour for pathspecs matching attributes in subdirectories”
  1. Matthew HughesJul 6, 2023
  2. Junio C HamanoJul 6, 2023
  3. Matthew HughesJul 6, 2023
  4. Matthew HughesJul 6, 2023
  5. Junio C HamanoJul 6, 2023
  6. Matthew HughesJul 7, 2023
  7. Junio C HamanoJul 7, 2023
  8. Eric SunshineJul 7, 2023
  9. Matthew HughesJul 8, 2023

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.