#556584 git-ls-files: exclude patterns don't affect tracked files

Package:
git
Source:
git
Description:
fast, scalable, distributed revision control system
Submitter:
Christian Ohm
Date:
2010-05-15 21:22:01 UTC
Severity:
wishlist
#556584#5
Date:
2009-11-16 22:56:59 UTC
From:
To:
Hello,

As the subject says, the exclude options to ls-files seem broken. For example,
in a repo with PNG files, "git ls-files" obviously lists those, but "git
ls-files -x '*.png'" does as well. --exclude also doesn't help, putting the
pattern into a file and using -X also fails.

Best regards,
Christian Ohm

#556584#10
Date:
2009-11-18 13:16:05 UTC
From:
To:
Hi Christian,

Christian Ohm wrote:
in the index are not ignored, and so with git ls-files, too.  This was
broken for a while, impacting other commands; see
<http://thread.gmane.org/gmane.comp.version-control.git/129889>, for
example.

Hackish workaround: use '-i', which (since v1.6.5.3) does not apply this
logic, with --exclude-from=file, file as follows:

	!*.png
	*

The logic being "I do not want to track anything but image files; now please
let me know what seems to be tracked by mistake."

Does that take care of your need?  What do you use this command to do?

Yours,
Jonathan
A bystander, who notices the documentation bug here, but hopes there is
something else, too

#556584#15
Date:
2009-11-18 14:16:15 UTC
From:
To:
Ok... I have a repo (Warzone 2100) with random files, some source code, some
data (e.g. png files). Now I want to use cscope to navigate the source, so I
use the following (generic) script to index the files:

if [ ! "$PROJDIR" ] ; then
        PROJDIR="`pwd`"
fi

if [ -d .git ] ; then
        git ls-files | sort | cscope -R -b -i- -f"$PROJDIR"/cscope.out
else
(
  cd /;
  find "$PROJDIR" -name '\.git' -name '\.svn' -name '\.hg' -prune -o -name \*.c -o -name \*.h -o -name \*.l -o -name \*.y -o -name \*.cpp -o -name \*.cc |
    sort |
    cscope -R -b -i- -f"$PROJDIR"/cscope.out
)
fi

That works, and the git ls-files line is much more convenient than the find
below, since it lists only the tracked files, not anything else.

But I'd also like to exclude the data files, since they take unneccessary time
to process, and occasionally lead to false positives. So I looked at the
git-ls-files man page, and saw the exclude options, which looked exactly like
what I wanted: "show me all files in the repo, except the following."

Reading further, the "Exclude patterns" section says "git-ls-files can use a
list of "exclude patterns" when traversing the directory tree and finding
files to show when the flags --others or --ignored are specified", so it is
somewhat documented, though missing from the description of the exclusion
options above (and if this is intentionally limited, some kind of explanation
would be nice).

Of course, I can just filter out unwanted files with grep or something, but
the -X option would have made it very easy to just have a project-specific
.cscope-ignore file that I can just feed to git ls-files.

Best regards,
Christian Ohm

#556584#20
Date:
2009-11-20 07:14:40 UTC
From:
To:
clone 556584 -1 -2
retitle -1 ls-files(1) doesn’t explain which files exclude patterns apply to
retitle -2 ls-files(1): document that filename arguments are glob patterns
severity -1 minor
severity -2 minor
retitle 556584 git-ls-files: exclude patterns don’t affect tracked files
severity 556584 wishlist
tags 556584 + wontfix
thanks

Hi Christian,

Christian Ohm wrote:

	git ls-files -- \*.c \*.h \*.l \*.y \*.cpp \*.cc \*.tcc |
	sort |
	cscope -R -b -i- -f"$PROJDIR"/cscope.out

So here’s another documentation bug: nowhere in the git-ls-files man page
does it explain that the filenames it takes are glob patterns.

(If you want to take patterns from a file, the shell makes this a little
trickier than I would like.  At least

	<.cscope-files xargs -d "\n" git ls-files --

works as expected.)

Right.  The -X option is already used by some commands (e.g., git-gui) to
support .gitignore, so I do not think it can be used for this.  I am not
sure whether adding an option that can be used would be worth the
complication, but if you have some idea of how this should work, you or I
could try sending a patch.

Thanks for the explanation.

Best wishes,
Jonathan

#556584#31
Date:
2009-12-15 03:36:37 UTC
From:
To:
Hi again,

Christian Ohm wrote:

#556584#36
Date:
2009-12-15 15:54:13 UTC
From:
To:
Thanks for your explanations. I've solved my problem with grep, that works fine
(though the patterns are different). My main complaint was that the program
doesn't do what the man page says; I don't know which is right, but behaviour
and explanation should correspond (and ideally include some explanations of
idiosyncrasies).

Best regards,
Christian Ohm

#556584#41
Date:
2009-12-15 20:03:05 UTC
From:
To:
| I would not be opposed to a patch to add an option that means "exclude
| these index entries from the output list." And for the sake of backwards
| compatibility, it may even be reasonable to call that option "-x".

That makes sense.  Sorry for the spam.