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

ε祈祈猫儿з 提交于 2019-12-22 01:51:49

问题


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?


回答1:


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.




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/5671406/force-svneol-style-native-on-the-server

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