jisaacks/GitGutter

Compare against branch indicates no changes and differs from "git diff <branch>"

Pyrdon opened this issue · 4 comments

Changing branch to compare against gives me no changes compared to git diff . After adding some debug printouts to git_gutter it seems like the temporary files it creates for comparison relates to a completely different project (I have several sublime projects open in parallel). Any ideas?

  • Sublime Text 4121
  • Platform: linux
  • Arch: x64
  • GitGutter 1.11.7
  • Install via PC: True
  • git version 2.20.1
  • mdpopups 4.2.1
  • markdown 3.2.2
  • pygments 2.1a0
  • jinja2 2.10.1

Temporary files are created using python's tempfile.mktemp() function. Maybe it returns equal names if too many files/projects are open?

Also note, GitGutter just calls view.set_reference_document() to give ST's internal minidiff something to compare against. So what you see on gutter may differ from plain git diff results, especially after heavy text manipulation it is known to "get out of sync" resulting in lower accuracy.

It was not related to the temporary files. After a few hours of debugging through print statements I found the culprit to be the encoding. The branch I was comparing with had a swedish comment and the character 0xC5 ('Å'). Fixing that and the comparison works as expected. An error printed to the console would be helpful here, or possible a message in the statusbar?

def _decode_diff(self, results):
        encoding = self.view_cache.python_friendly_encoding()
        try:
            decoded_results = results.decode(encoding)
        except AttributeError as e:
            # git returned None on stdout
            decoded_results = ''
        except UnicodeError:
            try:
                decoded_results = results.decode('utf-8')
            except UnicodeDecodeError as e:
                print("unicode: {}".format(str(e))) # Get here
                decoded_results = ''
        except LookupError:
            try:
                decoded_results = codecs.decode(results)
            except UnicodeDecodeError as e:
                decoded_results = ''
        print("Decoded '{}' for view '{}'".format(decoded_results,self.view.file_name()))
        # cache the diff result for reuse with diff_popup.
        self._git_diff_cache = decoded_results
        return self.process_diff(decoded_results)

Yeah, I have this issue too. Do the devs have the time/energy/will to fix this bug by any chance?