Force svn:eol-style=native on the server?
Asked Answered
L

3

14

Currently, in order to ensure the subversion property eol-style is set to native for each new file added to our project, we have to add this to the ~/.subversion/config file on each of our developers machines:

[miscellany]
enable-auto-props = yes

[auto-props]
*.java = svn:eol-style=native

Is there a way to do the equivalent on the svn server?

Lamdin answered 15/4, 2011 at 1:6 Comment(0)
B
9

No there is not.

You can use a hook scripts to look for the property to be set or not, but apart from that it's not possible. Subversion, differently than CVS, cannot change the content of the code coming from a commit.

The SVN book includes a note about this question:

Warning

Do not attempt to modify the transaction using hook scripts. A common example of this would be to automatically set properties such as svn:eol-style or svn:mime-type during the commit. While this might seem like a good idea, it causes problems. The main problem is that the client does not know about the change made by the hook script, and there is no way to inform the client that it is out-of-date. This inconsistency can lead to surprising and unexpected behavior.

Instead of attempting to modify the transaction, it is much better to check the transaction in the pre-commit hook and reject the commit if it does not meet the desired requirements.

Brogue answered 15/4, 2011 at 13:50 Comment(2)
Interesting. Thanks for the link. It sounds like this is the way to go: "Instead of attempting to modify the transaction, it is much better to check the transaction in the pre-commit hook and reject the commit if it does not meet the desired requirements."Lamdin
Why is this outdated?Brogue
I
7

Just because answer of Fausto now is outdated after release Subversion 1.8


In case of Subversion 1.8 or later you can use at the repository level (not globally for all repositories on server) repository dictated configuration (see also topic in Collab's blog), namely - svn:auto-props in the root of trunk of every repository

Intone answered 4/8, 2013 at 5:32 Comment(3)
Could you please point me to how to setup that repository dictated configuration? Those links only show how to read it, and I can't seem to get anything from Google either.Marrowfat
Well, I found a way through TortoiseSVN's Repository Browser but a console way is interesting too.Marrowfat
This answer is helpful, but needs clarification. Th OP is looking for an equivalent of auto-props, but enforced on the server. This answer points out the new and useful SVN 1.8 client store-in-repository svn:auto-props inheritable-property feature, but importantly 1) this is a client-side feature - an older SVN client e.g. 1.7 won't use it at all, and the props won't be enforced, and 2) even an SVN 1.8 client can to svn add --no-auto-props, and again, nothing is enforced. In summary, you need a hook.Armstrong
F
0

I couldn't find an example of how to check for svn:eol-style property for source code in the pre-commit hook script directly. The closest is the check-mime-type.pl which uses mime-type properties to determine if a file is a text file.

The following script inserted into the pre-commit script file will check that all the .cpp/.h files added in a commit have the svn:eol-style property set. (It can easily be extended to check additional file extensions). It will also provide messages to indicate which files are missing the svn:eol-style property.

REPOS="$1"
TXN="$2"

# Get new cpp/h files
ADDFILES=$(${SVNLOOK} changed "$REPOS" -t "$TXN" | sed -n -e '/^A.*\(\.cpp\|\.h\)$/s/^A *//p')
#echo "ADDFILES=$ADDFILES" >&2

# Check files for svn:eol-style property
ESMISSING=''
for f in ${ADDFILES}
do
  if [[ "$(${SVNLOOK} pl ${REPOS} -t ${TXN} ${f})" != *svn:eol-style* ]]
  then
    # output to stderr to include message in svn commit ouput
    echo "No svn:eol-style property set on file $f" >&2
    ESMISSING=1
  fi
done

if [[ -n "$ESMISSING" ]]
then
  exit 1
fi
Fatigued answered 4/8, 2013 at 4:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.