Browse files

normalize line endings before diffing

  • Loading branch information...
1 parent a0c3bda commit 85a2cae04a9b127bbe09ec338e4a8da32686dbe9 @fogleman fogleman committed Dec 13, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 git_gutter_handler.py
View
10 git_gutter_handler.py
@@ -29,6 +29,8 @@ def update_buf_file(self):
chars = self.view.size()
region = sublime.Region(0,chars)
contents = self.view.substr(region).encode("utf-8")
+ contents = contents.replace('\r\n', '\n')
@bizoo
bizoo added a note Dec 14, 2012

I'm pretty sure that the buffer of ST2 contains only '\n'.
ST2 normalize line ending to '\n' when reading file and convert them back to Windows/Linux/OSX line ending when writing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ contents = contents.replace('\r', '\n')
f = open(self.buf_temp_file.name,'w')
f.write(contents)
f.close()
@@ -41,7 +43,13 @@ def update_git_file(self):
self.git_temp_file.truncate()
args = ['git','--git-dir='+self.git_dir,'--work-tree='+self.git_tree,'show','HEAD:'+self.git_path]
try:
- subprocess.call(args, stdout=self.git_temp_file)
+ proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ contents = proc.stdout.read()
+ contents = contents.replace('\r\n', '\n')
+ contents = contents.replace('\r', '\n')
+ f = open(self.git_temp_file.name,'w')
+ f.write(contents)
+ f.close()
ViewCollection.update_git_time(self.view)
except Exception:
pass

0 comments on commit 85a2cae

Please sign in to comment.