From 53f0f7e264e92ce65e0e332dfed7a451f74a3797 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Tue, 29 Jun 2021 13:06:23 -0500 Subject: [PATCH 1/4] Diff missing unchanged lines --- lib/views/last_commit.erb | 3 +++ lib/views/status.erb | 3 +-- lib/web_git.rb | 5 ++--- lib/web_git/diff.rb | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 lib/views/last_commit.erb diff --git a/lib/views/last_commit.erb b/lib/views/last_commit.erb new file mode 100644 index 0000000..8a401c3 --- /dev/null +++ b/lib/views/last_commit.erb @@ -0,0 +1,3 @@ +
+  <%= diff %>
+
diff --git a/lib/views/status.erb b/lib/views/status.erb index a19a08c..968733a 100644 --- a/lib/views/status.erb +++ b/lib/views/status.erb @@ -191,8 +191,7 @@
- + <%= erb :last_commit, locals: { diff: @last_diff_html } %>
diff --git a/lib/web_git.rb b/lib/web_git.rb index 66eb3f9..78815de 100644 --- a/lib/web_git.rb +++ b/lib/web_git.rb @@ -52,10 +52,9 @@ class Server < Sinatra::Base @diff = Diff.diff_to_html(git.diff.to_s) last_diff = nil if git.log.count > 1 - last_diff = git.diff(git.log[1], "HEAD").to_s + "\n" + last_diff = git.diff("HEAD~1", "HEAD").to_s + "\n" end - # @last_diff_html = Diff.last_to_html(last_diff) - @last_diff_html = last_diff + @last_diff_html = Diff.last_to_html(last_diff) @branches = git.branches.local.map(&:full) logs = git.log diff --git a/lib/web_git/diff.rb b/lib/web_git/diff.rb index 51fbb5a..3dd9368 100644 --- a/lib/web_git/diff.rb +++ b/lib/web_git/diff.rb @@ -115,7 +115,7 @@ def self.get_last_diff end def self.get_last_left(diff) - filenames = get_file_names(get_last_commit_hash) + filenames = get_file_names("HEAD~1") files = file_diffs(diff) ones = {} files.each_with_index do |file, i| @@ -139,7 +139,7 @@ def self.get_last_left(diff) end def self.get_last_right(diff) - filenames = get_file_names(get_last_commit_hash) + filenames = get_file_names("HEAD~1") files = file_diffs(diff) ones = {} files.each_with_index do |file, i| From 15785c71f56b0950c8563d2010ced77d7646e231 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Tue, 29 Jun 2021 13:36:27 -0500 Subject: [PATCH 2/4] Remove unnecessary partial --- lib/views/last_commit.erb | 3 --- lib/views/status.erb | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 lib/views/last_commit.erb diff --git a/lib/views/last_commit.erb b/lib/views/last_commit.erb deleted file mode 100644 index 8a401c3..0000000 --- a/lib/views/last_commit.erb +++ /dev/null @@ -1,3 +0,0 @@ -
-  <%= diff %>
-
diff --git a/lib/views/status.erb b/lib/views/status.erb index 968733a..d3d5f1e 100644 --- a/lib/views/status.erb +++ b/lib/views/status.erb @@ -191,7 +191,9 @@
- <%= erb :last_commit, locals: { diff: @last_diff_html } %> +
+                      <%= diff %>
+                    
From 142b04d71e91fc7045c2b8eea3383c444a5d9dc9 Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Tue, 29 Jun 2021 13:46:36 -0500 Subject: [PATCH 3/4] Fix local variable, fix height --- lib/views/status.erb | 2 +- lib/web_git/diff.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/views/status.erb b/lib/views/status.erb index d3d5f1e..865b4c7 100644 --- a/lib/views/status.erb +++ b/lib/views/status.erb @@ -192,7 +192,7 @@
-                      <%= diff %>
+                      <%= @last_diff_html %>
                     
diff --git a/lib/web_git/diff.rb b/lib/web_git/diff.rb index 3dd9368..0ed015e 100644 --- a/lib/web_git/diff.rb +++ b/lib/web_git/diff.rb @@ -172,7 +172,7 @@ def self.last_to_html(diff) html_output += '' - html_output += '
' + html_output += '
' left_hash.keys.each do |file| html_output += '
' html_output += '

' + file + '

' From d14f57498231bd8b39f8847a59b2d4699ecbb1bd Mon Sep 17 00:00:00 2001 From: Jelani Woods Date: Tue, 29 Jun 2021 14:10:07 -0500 Subject: [PATCH 4/4] Hide empty unchanged lines from diff --- lib/views/status.erb | 7 +++++-- lib/web_git/diff.rb | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/views/status.erb b/lib/views/status.erb index 865b4c7..48bf557 100644 --- a/lib/views/status.erb +++ b/lib/views/status.erb @@ -10,6 +10,9 @@ ' html_output += '
' left_hash.keys.each do |file| - html_output += '
' + html_output += '
' html_output += '

' + file + '

' html_output += Diffy::Diff.new( left_hash[file], right_hash[file], - :include_plus_and_minus_in_html => true + :include_plus_and_minus_in_html => true, + :allow_empty_diff => false ).to_s(:html) html_output += '
' end