开发者

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

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开发者_如何学C on the svn server?


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.


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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜