35

With the svn:ignore property, is there a way I can specify what I want to ignore based on patterns which I don't want to ignore? In other words, I want to ignore everything but files ending in .xyz. How would I go about doing that (if it's even possible)?

One option I've explored is committing everything I want to be versioned, then setting the svn:ignore property on the directory to be '*', thus meaning no other files but what I've already committed will be versioned. This is the best I can come up with, but it feels dirty in that if I ever did need to add another file to be version, I'd have to make multiple commits... one to remove the svn:ignore property, another to add/commit the new file(s), and then a third to change svn:ignore back to '*'.

Your thoughts?

bahrep
  • 29,961
  • 12
  • 103
  • 150
whaley
  • 16,075
  • 10
  • 57
  • 68

6 Answers6

19

Have a look at Using negative patterns for Subversion's svn:ignore property. Obviously you can use "!" in character groups to negate its meaning. So if you want to ignore everything except files ending with .java, set the following pattern to svn:ignore:

*[!j][!a][!v][!a]
*.java?*
BSMP
  • 4,596
  • 8
  • 33
  • 44
tomka
  • 375
  • 1
  • 4
  • 9
  • 4
    I actually asked jcscoobyrs (who manages the svn package on OSX) about this on IRC that day which resulted in his post to thoughtspark.org. I reference it in a comment to the accepted answer. Just goes to show that no matter how awesome stackoverflow.com is, it still can't beat talking to a project committer on IRC. – whaley Oct 21 '10 at 14:59
  • The correct one would be: *[!j][!a][!v][!a] *j[!a][!v][!a] *ja[!v][!a] *jav[!a] – Nux Dec 16 '12 at 13:47
  • 1
    Link is broken. – James Jan 11 '17 at 04:07
  • `*[!a]` `*[!v]a` `*[!a]va` `*[!j]ava` `*[!.]java` current solution doesn't ignore anything that ends in a and it would ingore my.javaParser.java – Rick Apr 07 '17 at 18:00
13

No, there is no exclusive matching like you described. This article lists the possibilities for pattern matching. It's limited to:

  • ? - Matches any single character
  • * - Matches any string of characters, including the empty string
  • [ - Begins a character class definition terminated by ], used for matching a subset of characters

A similar question was asked already here.

bahrep
  • 29,961
  • 12
  • 103
  • 150
mkoeller
  • 4,469
  • 23
  • 30
  • 1
    There is a little bit more the `fnmatch` than mentioned in this answer. See tomka's answer below http://docs.python.org/2/library/fnmatch.html – vinnyjames Apr 19 '13 at 18:16
9

That's the only solution I know of. You can explicitly add files even if they are ignored though.

You would need to add that setting on all subdirectories though.

# Create a repository with property ignore *

[wlynch@orange ~] cd /tmp
[wlynch@orange /tmp] svnadmin create foo
[wlynch@orange /tmp] svn co file:///tmp/foo co
Checked out revision 0.
[wlynch@orange /tmp] cd co
[wlynch@orange co] svn propset svn:ignore \* .
property 'svn:ignore' set on '.'

# Create 3 files

[wlynch@orange co] touch a
[wlynch@orange co] touch b
[wlynch@orange co] touch c

# We can add all 3 of these files in one transaction

[wlynch@orange co] svn status
M     .
[wlynch@orange co] svn add a
A         a
[wlynch@orange co] svn add b
A         b
[wlynch@orange co] svn status
M     .
A      a
A      b
[wlynch@orange co] svn add c
A         c
[wlynch@orange co] svn ci
Sending        .
Adding         a
Adding         b
Adding         c
Transmitting file data ...
Committed revision 1.
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
  • 1
    Thanks for the tip. I did not realize you could explicitly add files as apparently `svn add` ignores svn:ignore. – whaley Jul 17 '09 at 13:42
  • For TortoiseSVN (1.8) users, it gets mad at you if you try to add an ignored file through its gui, but you can do so through the command line. – AlexMA Sep 04 '13 at 18:18
5

This is what I have set on bin folder for svn:ignore property to match everything except apk files:

*[!a][!p][!k]
*a[!p][!k]
*ap[!k]

If there would be full RegExp support you could use negative lookbehind, but that's rarely implemented anyway (e.g not in JavaScript) and is inefficient.

Nux
  • 9,276
  • 5
  • 59
  • 72
4

The following works for me and gets rid of a few quirks of the other suggestions.

*.?
*.??
*.???
*.[!j]???
*.?[!a]??
*.??[!v]?
*.???[!a]
*.?????*

A line by line explanation follows:

  • ignore everything that has a one-letter extension
  • ignore everything that has a two-letter extension
  • ignore everything that has a three-letter extension
  • ignore everything that has a four-letter extension where the extension's first letter is not j
  • ignore everything that has a four-letter extension where the extension's second letter is not a
  • ignore everything that has a four-letter extension where the extension's third letter is not v
  • ignore everything that has a four-letter extension where the extension's fourth letter is not a
  • ignore everything that has a five-letter extension or more

Limitations:

  • This will also block directories that end on .java
  • Unfortunately I was not able to ignore files without extension, since that would also block directories.
Cerno
  • 751
  • 4
  • 14
0

Well, I don't know if I miss something, but you can use any pattern you want:

svn propset svn:ignore "*~" .

You can check with:

svn propget svn:ignore .

Another way is to use an alias / script that can do complex parsing when committing.

The best solution I find to use myself is to completely separate the versioned tree of source files from the build tree. This way you do not generate things in your versioned tree of a directory. Then you can only use svn:ignore to ignore simple artefacts generated by text editors for example.

EDIT:

Sorry my mistake for the first solution, I have misread your post. The two other ways seems relevant even if not exactly what you want...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
neuro
  • 14,948
  • 3
  • 36
  • 59
  • I think your first solution is on to something, though. Could you conceivably set svn:ignore to a regular expression that matches everything except files that end in ".xyz"? – jprete Jul 16 '09 at 14:17
  • @jprete no regexes are allowed unfortunately. the pattern matching is based off of fnmatch. – whaley Jul 17 '09 at 13:44