.gitignore files not in a set - regex

Is there a way to limit the filetypes tracked by git by specifying a set of acceptable file types in .gitignore?
I want to be able to limit the filetypes commited to my compiled directory. I understand that the parser is not regex but I'd like something like this.
!src/(*.js|*.html|*.css)

You can just do
src/*
!src/*.js
!src/*.css
!src/*.html

Related

Git - Ignore directories based on their contents

Using .gitignore, is there a way to ignore a directory if it contains a certain file (or directory)?
This would be something like look-ahead assertions, though my use case is a little different: I want to ignore Mercurial repos in my project, to keep from accidentally committing them as part of the project. That is, I want to ignore all directories containing .hg, not just .hg itself.
I can work around this using the answer from this question, adding each directory name to .gitignore, but I'd like to make it more general if I can.
There is no way to do it beside adding all of them to your .gitignore file.
What you can do it to write a scipt which append all the desired paths to your .gitignore.
The content of .gitignore is alist of paths so git can be configured based upon content.
Each line in a gitignore file specifies a pattern

Filter for .h and .cpp files (kdevelop)

on kdevelop, you can configure a file filter ( on top of project tree ). Normally, the project tree shows a lot of files with different extensions, e.g xy.conf, xy.prf, moc_xy.cpp, moc_xy.h and so on. I want hide all unnessary files with following regex: [^\moc][a-z]*\.(h|cpp). But if I use this regex, it shows me no files. Whats wrong with this regex?
I also, read this post but the answer: \.(h|c(pp)?)$ doesn't work.
Best regards, Chris
You can only show *.h/c/cpp files in your project by first excluding all files * and then adding these inclusive patterns for them.
Like this, e.g. add this to your .gitignore/.hgignore file:
*
!*.h
!*.c
!*.cpp
If you don't have such filter files, you can configure them in the kdevelop's project fileter by adding includes and excludes:
try this:
.(h|c(pp)?)$
it works when i tested it here

How to hgignore all files of a particular extension except in one directory and its subdirectories?

I would like to use the .hgignore file of Mercurial to ignore all files with file extension .tex, except those .tex files in one particular directory and whatever subdirectory of this directory.
I presume syntax: regexp will be required for this.
A brief explanation of the particular regular expression used, would also be very welcome, so that we can all learn a bit here.
Let's say you want to exclude the directory named exclude. The following regex would then match all files that end in .tex unless exclude/ comes somewhere before that:
^(?!.*\bexclude/).*\.tex$

Mercurial ignore part of a directory

Been fighting with Mercurial's .hgignore for a while under Windows.
I have a folder named Upload which is currently empty. I do want it tracked so I added a .empty file in it which work fine. I want this so that new developers doing an hg clone get the Upload document required for the application.
Thing is I never want the folder to be populated with anything on the source control itself (test uploads from a development machine).
Example:
If I add Public/image.jpg it wouldn't be tracked.
Additionally I would like it for sub directory to be tracked. So if developer adds
Upload/users/.empty I would like this to be tracked.
Is this possible with regex voodoo?
In mercurial (and unlike in svn and cvs) adding a file overrides the .hgignore file, so you can put this in your .hgignore:
^Uploads/.*
and your Upload/.empty that you added will still be created on update and thus they'll get the directory.
Getting it to ignore files in upload but not not ignore files in subdirectories in Upload could be done with:
^Uploads/[^/]*$
which says: ignore anything that Starts with Uploads and has no further slashes in it.
Really though, you should be creating Uploads with your build/install/configure script when possible, not with the clone/update.
Try putting
Uploads/(?!.empty)
in .hgignore in the root of the repository
Try
^Uploads\b.*/(?!\.empty)[^/]+$
This should match any path starting with Uploads where the text after the last slash (=filename) is anything but .empty.

.hgignore syntax for ignoring only files, not directories?

I have a problem which I can't seem to understand. I'm using TortoiseHg (version 0.7.5) on Windows but on Linux I have the same problem. Here it is:
My .hgignore file:
syntax: regexp
^[^\\/]+$
What I'm trying to achieve is to add to the ignore list the files which are in the root of the hg repository.
For example if I have like this:
.hg
+mydir1
+mydir2
-myfile1
-myfile2
-anotherfile1
-anotherfile2
.hgignore
I want myfile1(2) and anotherfile1(2) to be ignored (names are only for the purpose of this example - they don't have a simple rule that can be put in the hgignore file easily)
Is there something I'm missing because I'm pretty sure that regexp is good (I even tested it)? Ideas?
Is there a simpler way to achieve this? [to add to the ignore list files that are in the root of the mercurial repository]
I relayed this question in #mercurial on irc.freenode.net and the response was that you cannot distinguish between files and directories — the directory is matched without the slash that you're searching for in your regexp.
However, if you can assume that your directories will never contain a full-stop ., but your files will, then something like this seems to work:
^[^/]*\..*$
I tested it in a repository like this:
% hg status -ui
? a.txt
? bbb
? foo/x.txt
? foo/yyy
Adding the .hgignore file gives:
% hg status -ui
? bbb
? foo/x.txt
? foo/yyy
I .hgignore
I a.txt
which indicates that the a.txt file is correctly ignored in your root directory, but x.txt in the foo subdirectory is not. You can also see that a file named just bbb in the root directory is not ignored. But maybe you can add such files yourself to the .hgignore file.
If you happen to have a directory like bar.baz in your root directory, then this directory and all files within will be ignored. I hope this helps a bit.
Here is a dirty trick:
Create an empty file ".hidden" in your directory, than add to .hgignore:
^mydir/(?!\.hidden).+$
This will ignore all files in the directory except ".hidden".