Commit b372290f8db24be56fc35d8b5f0f8b95067be129

Thomas de Grivel 2022-01-17T16:05:51

fix commit view

diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index 896c52b..c6ed774 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -356,9 +356,12 @@ defmodule KmxgitWeb.RepositoryController do
   end
   defp show_op(conn, :commit, %{git: git, org: org, repo: repo}) do
     IO.inspect(git)
-    {:ok, diff} = GitManager.diff(Repository.full_slug(repo), "#{git.log1.hash}~1", git.log1.hash)
-    diff_html = Pygmentize.html(diff, "diff.patch")
-    diff_line_numbers = line_numbers(diff)
+    diff = case GitManager.diff(Repository.full_slug(repo), "#{git.log1.hash}~1", git.log1.hash) do
+             {:ok, diff} -> diff
+             _ -> nil
+           end
+    diff_html = diff && Pygmentize.html(diff, "diff.patch")
+    diff_line_numbers = diff && line_numbers(diff)
     conn
     |> assign(:commit, git.log1)
     |> assign_current_organisation(org)
diff --git a/lib/kmxgit_web/templates/repository/commit.html.heex b/lib/kmxgit_web/templates/repository/commit.html.heex
index 9627aa5..6e6880d 100644
--- a/lib/kmxgit_web/templates/repository/commit.html.heex
+++ b/lib/kmxgit_web/templates/repository/commit.html.heex
@@ -26,14 +26,16 @@
       <p>
         <%= @commit.message %>
       </p>
-      <div class="content_text">
-        <div class="line_numbers">
-          <pre><%= for ln <- @diff_line_numbers do %><%= link ln, id: ln, to: "##{ln}" %>
-          <% end %></pre>
-         </div>
-        <%= raw @diff_html %>
-      </div>
-      <hr/>
+      <%= if @diff_html do %>
+        <div class="content_text">
+          <div class="line_numbers">
+            <pre><%= for ln <- @diff_line_numbers do %><%= link ln, id: ln, to: "##{ln}" %>
+            <% end %></pre>
+          </div>
+          <%= raw @diff_html %>
+        </div>
+        <hr/>
+      <% end %>
     </div>
   </div>
 </div>