开发者

Can I make git-svn handle svn:eol-style?

开发者 https://www.devze.com 2022-12-17 04:27 出处:网络
A lot of svn repositories require ne开发者_StackOverflow中文版w files to have an svn:eol-style attribute. Is there any way to ensure that this happens with git-svn ?You can try setting autoproperties

A lot of svn repositories require ne开发者_StackOverflow中文版w files to have an svn:eol-style attribute. Is there any way to ensure that this happens with git-svn ?


You can try setting autoproperties ([1][2]) in subversion config. It will ensure that during the add operation of new files svn:eol-style is set properly.

AFAIU git-svn is just using svn in inner workings, and it should load the subversion configuration, and set auto-props for new files.

Ok, I tested it, it works.

Example .subversion/config:

[miscellany]
enable-auto-props = yes

[auto-props]
*.cpp = svn:keywords=Id Revision;svn:eol-style=native
*.cs = svn:keywords=Id Revision;svn:eol-style=native


@silk's answer above is only a partial solution. A complete solution also includes configuring git to convert CRLF to LF on commit. So, in addition to what @silk suggests, you should also do:

git config --global core.autocrlf input
git config --global core.safecrlf warn

Or:

git config --global core.safecrlf warn
git config --global core.attributesfile ~/.gitattributes
echo '* text=auto' >> ~/.gitattributes

Explanation:

In my experience, git-svn will set the svn:eol-style=native attribute on commit, as @silk describes, but will not actually convert the committed files to LF line endings before committing. So, any CRLF line endings will be committed to the subversion repo intact, but subversion expects all svn:eol-style=native attributed files to be stored with LF line endings. The end result is that the first time someone edits and commits such a file from a subversion working copy, the diff will include CRLF to LF conversion.

So, a complete solution should include forcing git to convert files to LF line endings before committing. You can do this by setting core.autocrlf=input, which means "convert all CRLF to LF on commit, but don't do the reverse conversion on checkout", and core.safecrlf=warn or core.safecrlf=true, which will warn or stop you when you try to commit a file with CRLF line endings. The autocrlf setting will ensure these CRLFs get converted, so the safecrlf=true is probably excessive. See git help config.

Alternatively, you can use git attributes to force the conversion, by setting text=auto on all files. To do this globally, you need to specify an attributes file in core.attributesfile. See git help attributes.


Consider using SubGit.

From the very first builds it supports proper Subversion properties to .gitattributes/.gitignore conversion (and vice versa). Amongst other things that includes svn:eol-style and 'eol', svn:mime-type and 'text', svn:ignore and .gitignore conversion.

SubGit is a server-side solution — one has to install it into Subversion repository. After that one can use any Subversion or Git client to send changes into this repository. Please refer to SubGit documenration to get more details. In general it's fairly easy to use it:

  1. Generate SubGit configuration file:

    $ subgit configure svn_repos
    
  2. Adjust svn_repos/conf/subgit.conf file as needed to specify Git repository location, branches & tags layout, etc.

  3. Finish the installation:

    $ subgit install svn_repos
    

At this moment SubGit converts all the revisions from your Subversion repository to Git repository. Then it installs its custom hooks to be triggered by incoming modifications. This way SubGit continuously converts Subversion revisions on every svn commit and Git commits on every git push.

SubGit is a commercial project, but it's free for small teams, open-source and academic projects. And I'm one of SubGit developers.

0

精彩评论

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