25

I find that it is best practice to have all text files have svn:eol-style=native property set. But what's the most efficient way to do it?

I develop programs mainly on Windows(using TortoiseSVN and svn.exe command line) and sometimes write portable C/C++ libraries for Windows and Linux. In order to prevent the nasty mix-CR,LF problem on my source files, I think svn:eol-style=native should be the "default", but unfortunately it is not.

I know from Subversion Red Book that configuring [auto-props] in ~/.subversion/config or %APPDATA%\Subversion\config helps, however, it is per client setting. What about some developer in my team forget to configure those config files (think about dev on multiple virtual machines)? Even all do remember, what if some new kind of text file extension-name occurs? How do I properly propagate this change to all config file on all dev machines in my team?

All seems to be a cumbersome process.

Lii
  • 11,553
  • 8
  • 64
  • 88
Jimm Chen
  • 3,411
  • 3
  • 35
  • 59
  • 1
    Related: [Force svn:eol-style=native on the server?](http://stackoverflow.com/questions/5671406/force-svneol-style-native-on-the-server) – blahdiblah Sep 27 '12 at 01:04

3 Answers3

22

What about some developer in my team forget to configure those config files(think about dev on multiple virtual machines)?

Just fix error.

If you find a file that was incorrectly checked in, it's not too hard to fix. First, change the file to the correct line-ending style for your platform. Any programming editor should be able to switch styles with some built-in command, or you can use a 'fromdos' or 'todos'-type utility. Once it's fixed, set the property and check it in:

 svn propset svn:eol-style native filename
 svn commit filename

Copy of my comment:

Another suggestion is to use pre-commit hook, check svn:eol-style settings (and presence) and fix if needed

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • 1
    Another suggestion is to use pre-commit hook, check svn:eol-style settings (and presence) and fix if needed – Lazy Badger Nov 06 '11 at 09:36
  • May be a good idea. Can pre-commit hook silently add svn:eol-style=native property to committed file just before committing to the repository? When svn client does 'svn update' next time, he gets that property automatically. – Jimm Chen Nov 10 '11 at 12:06
  • I think - it can: you can use any commands in hook-script. I don't kbow only how to get file-list for files in commit and single file from list – Lazy Badger Nov 10 '11 at 14:36
  • Until svn 1.7, I have to confess installing a pre-commit hook is the most viable way. Please COPY your first comment to your answer body and I'll mark it accepted. Thanks. BTW: "get file list" of a commit is easy with svnlook.exe , so there is no techninal barrier now. – Jimm Chen Sep 28 '12 at 07:07
14

Subversion 1.8 way

Because Subversion 1.8 got repository dictated configuration (RDC), for mandatory using common settings by all clients for a given repository, property can and have to be configured in the repository root (or trunk)

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
9

This should be a quick answer, not "dive into details and get it yourself, here is the link" version.

We'll just f-ing do it, okay? For subversion 1.8+:

$ cd my_checkout_dir

$ svn propset svn:auto-props '
### src
*.c = svn:eol-style=native
*.cpp = svn:eol-style=native
*.h = svn:eol-style=native
*.pch = svn:eol-style=native
*.lua = svn:eol-style=native
*.py = svn:eol-style=native
*.pl = svn:eol-style=native
*.txt = svn:eol-style=native
*.sh = svn:eol-style=native;svn:executable
### ui
*.xib = svn:eol-style=native
*.ui = svn:eol-style=native
*.qrc = svn:eol-style=native
### project
*.pro = svn:eol-style=native
*.pbxproj = svn:eol-style=native
*.json = svn:eol-style=native
*.xcworkspacedata = svn:eol-style=native
*.plist = svn:eol-style=native
' .

$ svn commit -m 'Got really tired of svn:eol-style issues'

Please note closing single-quote and dot (i.e. current dir) at the end. Tune this list for your needs, copy svn propset svn:auto-props '…' . into unix/msys sh-terminal (yes, with Enters). After commit, all files below my_checkout_dir will inherit corresponding properties upon add. Files added before this action will not be modified. As you see in *.sh and below, you can add more properties via ;. If you want to change the list, just repeat everything again.

Here are defaults suggested by svn in my ~/.subversion/config for the reference:

### The format of the entries is:
###   file-name-pattern = propname[=value][;propname[=value]...]
### The file-name-pattern can contain wildcards (such as '*' and
### '?').  All entries which match (case-insensitively) will be
### applied to the file.  Note that auto-props functionality
### must be enabled, which is typically done by setting the
### 'enable-auto-props' option.
# *.c = svn:eol-style=native
# *.cpp = svn:eol-style=native
# *.h = svn:keywords=Author Date Id Rev URL;svn:eol-style=native
# *.dsp = svn:eol-style=CRLF
# *.dsw = svn:eol-style=CRLF
# *.sh = svn:eol-style=native;svn:executable
# *.txt = svn:eol-style=native;svn:keywords=Author Date Id Rev URL;
# *.png = svn:mime-type=image/png
# *.jpg = svn:mime-type=image/jpeg
# Makefile = svn:eol-style=native
user3125367
  • 2,920
  • 1
  • 17
  • 17