public
Description: The Git TextMate Bundle
Homepage: http://tim.theenchanter.com/
Clone URL: git://github.com/timcharper/git-tmbundle.git
Show 'git-diff --check' output when showing uncommitted changes.
mblsha (author)
Sun Jun 15 03:42:45 -0700 2008
commit  a0bfa4c0b6834596a78c8c12682b12458f079675
tree    4b7c0e9238e2a497e31e6ba6125275f5266e7ac9
parent  a58c7355bf37482ec5400b1877778bb872fec4d7
...
8
9
10
 
11
12
13
...
25
26
27
28
 
 
 
 
29
30
31
...
8
9
10
11
12
13
14
...
26
27
28
 
29
30
31
32
33
34
35
0
@@ -8,6 +8,7 @@ class DiffController < ApplicationController
0
     params[:context_lines] = git.config.context_lines if git.config.context_lines
0
     
0
     render("_diff_results", :locals => {
0
+ :diff_check_results => git.with_path(params[:git_path]).diff_check(params.filter(:path, :revision, :context_lines, :revisions, :branches, :tags, :since)),
0
       :diff_results => git.with_path(params[:git_path]).diff(params.filter(:path, :revision, :context_lines, :revisions, :branches, :tags, :since)),
0
       :git => git.with_path(params[:git_path])
0
     })
0
@@ -25,7 +26,10 @@ class DiffController < ApplicationController
0
     puts "<h2>Uncommitted Changes for ‘#{htmlize(paths.map{|path| shorten(path, base)} * ', ')}’</h2>"
0
     
0
     paths.each do |path|
0
- render("_diff_results", :locals => {:diff_results => git.diff(:path => path, :since => "HEAD") })
0
+ render("_diff_results", :locals => {
0
+ :diff_check_results => git.diff_check(:path => path, :since => "HEAD"),
0
+ :diff_results => git.diff(:path => path, :since => "HEAD")
0
+ })
0
       
0
       git.submodule.all(:path => path).each do |submodule|
0
         next if (diff_results = submodule.git.diff(:since => "HEAD")).blank?
...
1
2
3
 
 
 
 
 
 
4
5
6
...
1
2
3
4
5
6
7
8
9
10
11
12
0
@@ -1,6 +1,12 @@
0
 <% @diff_line_count = 0 %>
0
 <% revision ||= nil %>
0
 <code>
0
+ <% if not diff_check_results.empty? %>
0
+ <% diff_check_results.each do |diff_result| %>
0
+ <% render "diff/_diff_check_result", :locals => {:git => git, :diff_result => diff_result } %>
0
+ <% flush %>
0
+ <% end %>
0
+ <% end %>
0
   <% diff_results.each do |diff_result| %>
0
     <% next if @diff_line_count >= Git::DEFAULT_DIFF_LIMIT %>
0
     <% if diff_result[:mode] == Git::SUBMODULE_MODE %>
...
346
347
348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
350
351
...
355
356
357
 
 
 
 
 
358
359
 
360
361
362
...
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
...
372
373
374
375
376
377
378
379
380
 
381
382
383
384
0
@@ -346,6 +346,23 @@ module SCM
0
       command("rev-parse", "HEAD").strip
0
     end
0
     
0
+ def diff_check_output(options = {})
0
+ options = {:file => options} unless options.is_a?(Hash)
0
+ params = ["diff"]
0
+ params << ["--check"]
0
+
0
+ lr = get_range_arg(options)
0
+ params << lr if lr
0
+ params << make_local_path(options[:path]) if options[:path]
0
+
0
+ output = command(*params)
0
+ end
0
+
0
+ def diff_check(options = {})
0
+ output = diff_check_output(options)
0
+ parse_diff_check(output)
0
+ end
0
+
0
     def diff(options = {})
0
       options = {:file => options} unless options.is_a?(Hash)
0
       params = ["diff"]
0
@@ -355,8 +372,13 @@ module SCM
0
       params << lr if lr
0
       params << make_local_path(options[:path]) if options[:path]
0
       
0
+ check = diff_check_output(options)
0
+ if not check.empty?
0
+ check += "\n\n\n"
0
+ end
0
+
0
       output = command(*params)
0
- File.open("/tmp/output.diff", "w") {|f| f.puts output }
0
+ File.open("/tmp/output.diff", "w") {|f| f.puts check + output }
0
       parse_diff(output)
0
     end
0
     
...
140
141
142
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
145
146
...
140
141
142
 
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
0
@@ -140,7 +140,29 @@ module Parsers
0
     end
0
     output
0
   end
0
-
0
+
0
+ def parse_diff_check(diff_content)
0
+ output = []
0
+ current = nil
0
+ # puts "<pre>#{htmlize(diff_content)}</pre>"
0
+ diff_content.split("\n").each do |line|
0
+ case line
0
+ when /^([\w\/\.]+):(\d+):\s*(.+)$/
0
+ current = {}
0
+ current[:file_path] = $1
0
+ current[:file_line] = $2
0
+ current[:warning] = $3
0
+ current[:lines] = []
0
+ output << current
0
+ when /^\+(.*)$/ # insertion
0
+ current[:lines] << {:type => :insertion, :text => $1 }
0
+ when /^\-(.*)$/ # deletion
0
+ current[:lines] << {:type => :deletion, :text => $1 }
0
+ end
0
+ end
0
+ output
0
+ end
0
+
0
   def parse_diff(diff_content)
0
     output = []
0
     current = nil

Comments

    No one has commented yet.