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 ?
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With