Using svn:ignore to ignore everything but certain files

爷,独闯天下 提交于 2019-11-30 05:43:05
mkoeller

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.

Have a look at http://www.thoughtspark.org/node/38. 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?*

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.

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.

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.
neuro

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...

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!