Trying to clone a repository but the line endings are wrong
Asked Answered
C

1

20

I have cygwin and msysgit on my computer. I am trying to clone a repository for a vim package with this command:

cd ~/.vim/bundle
git clone https://github.com/jelera/vim-javascript-syntax.git

However, when I run vim, it fails, reporting error E488: Trailing characters. This appears to be cause by the line endings being CRLF rather than just LF, which is confirmed when I replace them.

Of course replacing them manually isn't what I want. I'd rather have git do it for me. However, as I am using my computer for developing on the Windows platform, I don't want to modify any global settings.

Is there a command line switch to have git clone a repo using LF EOLs only?

Cottbus answered 21/6, 2018 at 17:3 Comment(2)
Can someone help me improve my Q & A? I don't understand why I got downvoted.Cottbus
Looks like it was just a driveby downvoting. I don't see anything wrong. Only mods were just some minor formatting changes.Cottbus
C
32

Ok, so it turns out that a config key can be set at the command line using the -c switch. That would change my command to:

cd ~/.vim/bundle
git clone -c core.autocrlf=false https://github.com/jelera/vim-javascript-syntax.git

From git clone help:

--config <key>=<value>
-c <key>=<value>

    Set a configuration variable in the newly-created repository; this takes effect immediately after the repository is initialized, but before the remote history is fetched or any files checked out. The key is in the same format as expected by git-config[1] (e.g., core.eol=true). If multiple values are given for the same key, each value will be written to the config file. This makes it safe, for example, to add additional fetch refspecs to the origin remote.

and git config help:

core.autocrlf

    Setting this variable to "true" is the same as setting the text attribute to "auto" on all files and core.eol to "crlf". Set to true if you want to have CRLF line endings in your working directory and the repository has LF line endings. This variable can be set to input, in which case no output conversion is performed.

I've verified that this fixes the issue.

Cottbus answered 21/6, 2018 at 17:6 Comment(3)
Don't know why this got downvoted, it's the right answer.Thermoluminescent
@torek, yeah. Weird eh? And I don't know why the question was either. It seems like a reasonable question.Cottbus
Exactly what I was looking for.Seifert

© 2022 - 2024 — McMap. All rights reserved.