Commit 8a52300e2b72d650e43b9bbf3a928b957f27ee51

Thomas de Grivel 2022-11-04T05:22:50

use master as default branch

diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index a5c8ae4..0abe1d0 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -120,10 +120,14 @@ defmodule KmxgitWeb.RepositoryController do
       org = repo.organisation
       user = repo.user
       git = setup_git(repo, conn, op, op_params)
-      first_tree = case Enum.at(git.trees, 0) do
-                       {_, first_tree, _} -> first_tree
-                       nil -> nil
-                     end
+      first_tree = Enum.find_value(git.trees,
+        fn {:branch, "master", _} -> "master"
+          _ -> false
+        end) ||
+        case Enum.at(git.trees, 0) do
+          {_, first_tree, _} -> first_tree
+          nil -> nil
+        end
       tree1 = op_params.tree || first_tree
       op_params = %OpParams{op_params | tree: tree1, git: git, org: org, repo: repo, user: user}
       if git.valid do