Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-svn

A lot of svn repositories require new files to have an svn:eol-style attribute. Is there any way to ensure that this happens with git-svn ?

like image 244
krosenvold Avatar asked Jan 24 '10 14:01

krosenvold


People also ask

Can you use Git and SVN together?

git-svn is a specialized tool for Git users to interact with Git repositories. It works by providing a Git frontend to an SVN backend. With git-svn, you use Git commands on the local repository, so it's just like using normal Git. However, behind the scenes, the relevant SVN commands are sent to the server.

Why is Git preferred over SVN?

Many people prefer Git for version control for a few reasons: It's faster to commit. Because you commit to the central repository more often in SVN, network traffic slows everyone down. Whereas with Git, you're working mostly on your local repository and only committing to the central repository every so often.

Is SVN and Git are same?

The difference between Git and SVN version control systems is that Git is a distributed version control system, whereas SVN is a centralized version control system. Git uses multiple repositories including a centralized repository and server, as well as some local repositories.


2 Answers

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
like image 58
silk Avatar answered Nov 15 '22 20:11

silk


@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.

like image 28
ntc2 Avatar answered Nov 15 '22 19:11

ntc2