Sublime Forum

SublimeMerge showing additional bytes in the Staged Files diff when using GitPython repo.index.add method



consider this initial Working Directory in SublimeMerge:

If I run $ git add -- src/version.js I’d get this Staged Files diff

So far so good, the diff is correct… if we look at the hex content of that file:

you can see crlf bytes at the end.

Now, let’s unstage that file and repeat the same operation but this time using GitPython commands, if we do:

$ python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 18:54:59) [MSC v.1929 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ["GIT_PYTHON_TRACE"] = "full"
>>> import logging
>>> logging.basicConfig(level=logging.INFO)
>>> import git
INFO:git.cmd:git version -> 0; stdout: 'git version'
INFO:git.cmd:git version -> 0; stdout: 'git version'
>>> repo = git.Repo(os.getcwd())
>>> reader = repo.config_reader()
>>> repo.index.add(['src\\version.js'])
[(100644, ac3cbe8dabe6dde800e2cec55763cacdcb88a918, 0, src/version.js)]

and we look now to SublimeMerge we’ll see the diff of the Staged Files looks different now :face_with_raised_eyebrow:

Any idea what could be the reason of this behaviour? I don’t get it.

I guess my question is… what’s the meaning of that diff in SublimeMerge? Because If I look to the content of that file the hex content still remains the same (obviously).

Ps. Using GitPython==3.1.27 over here



That character is a carriage return; you get that kind of action when your git is set to try and fiddle line endings on files when it checks them out in order to make them conform to the local platform.



Yeah, I know 0x0D is CR and 0x0A is LF… What I don’t understand is, if the file content didn’t change (still was having CRLF as endlines), why did SublimeMerge started showing me this diff? I guess my question is, how do you interpret the diff of SublimeMerge in this particular case?

But anyway, I’ve talked with one of the maintainers of GitPython and he suggested me to not using that repo.index and just using the methods repo.git.add and repo.git.commit so regular git commands will be spawned without “screwing up” SublimeMerge diffs.

Still, I’m curious to know how to interpret these diffs on SublimeMerge, I guess that’s what my question is all about.



Perhaps related to telling Merge to ignore whitespace changes in diffs?



Hey @BPL,

This is likely to do with the autocrlf configuration and/or the text/eol git attributes.
When you get a chance, could you provide your Sublime Merge debug information via Help > Debug Information.

Before sharing this, take a moment to redact any sensitive config information such as paths, Git user information, remotes etc.

The Git Config and EOL information in the debug info should be of particular interest.

Kind regards,
- Dylan from Sublime HQ