Ignoring Line Ending Style with TextMate Subversion Diff
Are you like me? Does it annoy you when trying to track the changes in a file’s history, and hitting one revision where a contributor’s text editor used different line endings, and the entire file is shown as being changed? It kind of makes tracking revisions useless. Thankfully, in version 1.4+ of Subversion, you can instruct it to ignore line endings in the command line:
[bash]$ svn diff -x—ignore-eol-style foo.php[/bash]
I tend to do all of my work in TextMate, though, so a command line option isn’t handy. Thanks to TextMate’s open Bundle architecture, I was able to easily modify the Subversion bundle to ignore line ending style, but only when I want it to. Here’s how:
Right click on your TextMate application icon and select Show Package Contents. Navigate to Contents/SharedSupport/Bundles and copy Subversion.tmbundle to your desktop or another convenient location. Right click this copied bundle and select Show Package Contents. Open Support/svn_diff.rb in TextMate. Around line 34 you’ll see:
[ruby line=“34”]diff_arg = diff_cmd ? “—diff-cmd #{diff_cmd}” : ‘’[/ruby]
Below this, add the following:
[ruby line=“35”]ignore_eol = (ENV[‘SVN_DIFF_IGNORE_EOL’] == ‘TRUE’) ? ‘-x—ignore-eol-style’ : ‘’[/ruby]
And modify line 42 (now line 43) from:
[ruby line=“43”]res = %x{#{e_sh svn} 2>&1 diff “-r#{revision}” #{diff_arg} #{e_sh target_path}}[/ruby]
to:
[ruby line=“43”]res = %x{#{e_sh svn} 2>&1 diff #{ignore_eol} “-r#{revision}” #{diff_arg} #{e_sh target_path}}[/ruby]
Now in your TextMate Preferences, click Advanced, Shell Variables, and create a new shell variable named SVN_DIFF_IGNORE_EOL, and set it to TRUE to ignore line ending style, or FALSE (or any other value) if you do not wish to ignore line ending style. Note that these are not real boolean values, but text values, hence why the TRUE in the assignment of the ignore_eol variable in modified Ruby is quoted; it’s a string after all.
Save the file, and then just double-click your modified copy of the bundle, which will install it non-destructively, and your svn diffs will now respect your preference for whether or not you care about the line endings when examining differences between files under version control.