Any git / github gurus? Need help on line endings
#1
I'm trying to update an addon in the kodi xbmc-scripts repo.  IIUC I need to provide a PR to the source repo (in this case it's on XBMC-addons).

My problem is I develop on Windows.  When I fork the repo from XBMC-addons and clone it to my remote I want to create a new branch and add my changes as commits.  But it seems like I run into a problem where the text files on my remote are using CRLF in my editor.  From doing some research one solution seems to be to create a .gitattributes file in my remote repo to force text to eol=lf which I did.  Using .gitattributes it does seem like the files I checkout keep their UNIX LF line endings.  The problem is I end up with a commit of the .gitattributes in my history and can't generate a clean PR from my update branch to the XBMC-addons master.  So how do I avoid getting CRFL introduced in my edited files?  Or just remember to convert the line endings after editing and prior to doing the commit?

scott s.
.
maintainer of skin  Aeon MQ5 mods for post-Gotham Kodi releases:
Matrix
Leia see: 304472
Reply
#2
Why not just use vscode, notepad+ or any good editor that allows you to save files with just linefeeds?

Martin
Reply
#3
You may look at https://help.github.com/en/github/using-...ne-endings -> Global settings for line endings
core.autocrlf true: will checkout lineendings in windows style (CRLF) on your windows machine on checkout and will check them in in linux style (LF) on commit
see more at https://git-scm.com/book/en/v2/Customizi...figuration (search for core.autocrlf)

But be aware this is a global setting, it may effect other git-repos on your computer (especially those which were developed on windows only)
.gitattributes would be less invasive
Reply
#4
Thanks.  As I wrote, I can't figure out a way to use .gitattributes in the Kodi addon development workflow.  It works fine for a personal project.   I was thinking maybe something like core.autocrlf is the way I need to go.  I use np++ (also have ST 3 installed) and at least in np++ it seems like I have to manually select changing line endings from the menu on a per-file basis -- not helpful when doing a global find and replace for example (though I suppose I could also do a find-and-replace on the line endings as well, but needing to do that on every check-out is a pain).

scott s.
.
maintainer of skin  Aeon MQ5 mods for post-Gotham Kodi releases:
Matrix
Leia see: 304472
Reply
#5
ditch the broken os that think it is a type writer. problem solved.

/runs
Reply
#6
(2020-01-14, 16:52)spiff Wrote: ditch the broken os that think it is a type writer. problem solved.

/runs
I think he would have come up with this solution himself, if it was an option for him :-)

But more or less you are right, it's always difficult to handle different line-endings in source, you have to be very careful, especially if you started with one OS and then you switch to another (with different line endings)
Reply
#7
One last option would be:
  • Place your .gitattributes into the git-Folder
  • open the file: .git/info/exclude
  • write following at the end of the file:
    .gitattributes
Explaination:
  • .git/info/exclude is like a .gitignore, but won't be checked in
  • So you can use a .gitattributes put won't mess up with the repo
  • If you ever delete the whole repo (including .git) on your computer and make a new clone you have to manually put .gitattributes and the line in .git/info/exclude again (like already said, they aren't checked in)
Reply
#8
Hi,

as mentionend already
git config --global core.autocrlf true

is what you want.
The git-bash i use on windows had this enabled by default. It saved me quite often already from pushing \r .

If you want to clean up your local files i can recommend to go to the linux subsystem in win 10 and combine find and sed for that ... something like this ...
find ./ -type f -exec sed -i -e 's/\r//g' {} \;
note... this might need some fideling with the params


BR
Takezo
Reply
#9
I haven't given up on this, but got distracted by other things. I need to get this sorted so I can put up some PRs to provide Py3 updates to some abandoned addons that still are useful in my skin.  I should note I've been using github desktop which has come a long ways but maybe this is still beyond it.  I have git bash installed so can muck around in git if I have to.

scott s.
.
maintainer of skin  Aeon MQ5 mods for post-Gotham Kodi releases:
Matrix
Leia see: 304472
Reply
#10
(2020-02-05, 06:29)scott967 Wrote: I haven't given up on this, but got distracted by other things. I need to get this sorted so I can put up some PRs to provide Py3 updates to some abandoned addons that still are useful in my skin.  I should note I've been using github desktop which has come a long ways but maybe this is still beyond it.  I have git bash installed so can muck around in git if I have to.

scott s.
.

Did you try using git config --global core.autocrlf true ?
This is a pure "client" side setting. It only affects your development machine. It does exactly what you want. If you try to push something with CRLF it will remove the CR before the push but leaves it in your local files. 
So for your daily work this is fine. You will never again push a CRLF with this enabled.

If you need to clean up i personally would still go with the linux subsystem and find and sed however there is also the powershell...
"((Get-Content $file) -join "`n") + "`n" | Set-Content -NoNewline $file"
should work but there is a bit more to it it seems. https://stackoverflow.com/questions/1912...powershell
Reply
#11
Thanks.  I've been doing some man reading to better understand what core.autocrlf does.  I did find a glitch on my .gitattributes I was using as it was screwing up png files (header has PNG CR LF in it).  IIUC the autocrlf should when I switch to a branch show me my text files with cr-lf and when I open them in any text editor I can keep the cr-lf and just when I commit it will actually save the file with just the lf.  And I won't see any diffs generated due to line endings.  I think I am ready to do some experiments and check it out. I also see now the idea of going into the .git for a repo and making .gitattributes ignored.  That I can see for use on a per-repo basis, though I don't think I really need that.

scott s.
.
maintainer of skin  Aeon MQ5 mods for post-Gotham Kodi releases:
Matrix
Leia see: 304472
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
Any git / github gurus? Need help on line endings00