[OCaml] Mobile-friendly clone of cgit.
Handle repository filesystem errors
Changed files
lib/resolvers.ml
@@ -32,9 +32,23 @@
32
32
let path = full_path repo |> Fpath.v in
33
33
Store.v ~dotgit:path path
34
34
35
Added:
let default_repo_description = "Unnamed repository"
36
Added:
37
Added:
let read_description_file description_path =
38
Added:
try
39
Added:
match
40
Added:
In_channel.with_open_text description_path In_channel.input_all
41
Added:
|> String.trim
42
Added:
with
43
Added:
| "" -> default_repo_description
44
Added:
| description -> description
45
Added:
with Sys_error _ -> default_repo_description
46
Added:
35
47
let repo_description repo =
36
Removed:
let description_path = Filename.concat (full_path repo) "description" in
37
Removed:
In_channel.with_open_text description_path In_channel.input_all
48
Added:
if is_valid_repo_name repo then
49
Added:
let description_path = Filename.concat (full_path repo) "description" in
50
Added:
read_description_file description_path
51
Added:
else default_repo_description
38
52
39
53
let short_hash hash = String.sub hash 0 8
40
54
lib/views.ml
@@ -75,29 +75,54 @@
75
75
HTML.html [] [ head page_title; body body_data ]
76
76
end
77
77
78
Added:
let error_page message =
79
Added:
let open HTML in
80
Added:
respond
81
Added:
@@ html []
82
Added:
[
83
Added:
Page.head "Fatal Error";
84
Added:
body []
85
Added:
[
86
Added:
h1 [] [ txt "Fatal Error" ];
87
Added:
div
88
Added:
[ id "main" ]
89
Added:
[
90
Added:
p [] [ b [] [ txt "%s" message ] ];
91
Added:
p []
92
Added:
[
93
Added:
txt
94
Added:
"Your best course of action is to press the 'back' \
95
Added:
button in your browser.";
96
Added:
];
97
Added:
];
98
Added:
];
99
Added:
]
100
Added:
78
101
let root () =
79
Removed:
let all_repositories =
80
Removed:
(* Ignore hidden directories. *)
81
Removed:
let repos =
82
Removed:
Sys.readdir config.git_project_root
83
Removed:
|> Array.to_list
84
Removed:
|> List.filter (fun name -> not (name.[0] = '.'))
85
Removed:
|> List.sort String.compare
102
Added:
try
103
Added:
let all_repositories =
104
Added:
(* Ignore hidden directories. *)
105
Added:
let repos =
106
Added:
Sys.readdir config.git_project_root
107
Added:
|> Array.to_list
108
Added:
|> List.filter (fun name -> not (name.[0] = '.'))
109
Added:
|> List.sort String.compare
110
Added:
in
111
Added:
let li_of_repo repo =
112
Added:
HTML.li [] [ Routes.link_to (Routes.Repo repo) (txt "%s" repo) ]
113
Added:
in
114
Added:
HTML.(div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repos ])
86
115
in
87
Removed:
let li_of_repo repo =
88
Removed:
HTML.li [] [ Routes.link_to (Routes.Repo repo) (txt "%s" repo) ]
89
Removed:
in
90
Removed:
HTML.(div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repos ])
91
Removed:
in
92
Removed:
respond
93
Removed:
@@ Page.render
94
Removed:
{
95
Removed:
title = "Ogit";
96
Removed:
repo = None;
97
Removed:
subtitle = "Repositories for " ^ config.user;
98
Removed:
active = Summary;
99
Removed:
content = [ all_repositories ];
100
Removed:
}
116
Added:
respond
117
Added:
@@ Page.render
118
Added:
{
119
Added:
title = "Ogit";
120
Added:
repo = None;
121
Added:
subtitle = "Repositories for " ^ config.user;
122
Added:
active = Summary;
123
Added:
content = [ all_repositories ];
124
Added:
}
125
Added:
with Sys_error message -> error_page message
101
126
102
127
module Repo = struct
103
128
let page_title repo =
@@ -249,26 +274,3 @@
249
274
content;
250
275
}
251
276
end
252
Removed:
253
Removed:
let error_page message =
254
Removed:
let open HTML in
255
Removed:
respond
256
Removed:
@@ html []
257
Removed:
[
258
Removed:
Page.head "Fatal Error";
259
Removed:
body []
260
Removed:
[
261
Removed:
h1 [] [ txt "Fatal Error" ];
262
Removed:
div
263
Removed:
[ id "main" ]
264
Removed:
[
265
Removed:
p [] [ b [] [ txt "%s" message ] ];
266
Removed:
p []
267
Removed:
[
268
Removed:
txt
269
Removed:
"Your best course of action is to press the 'back' \
270
Removed:
button in your browser.";
271
Removed:
];
272
Removed:
];
273
Removed:
];
274
Removed:
]
test/test_ogit.ml
@@ -24,6 +24,20 @@
24
24
Unix.putenv "OGIT_CONFIG" "/tmp/custom-ogit.toml";
25
25
assert (Ogit.Config.locate_config_file () = "/tmp/custom-ogit.toml")
26
26
27
Added:
let test_description_reader () =
28
Added:
let file = Filename.temp_file "ogit-description" ".txt" in
29
Added:
Sys.remove file;
30
Added:
assert (
31
Added:
Ogit.Resolvers.read_description_file file
32
Added:
= Ogit.Resolvers.default_repo_description);
33
Added:
Out_channel.with_open_text file (fun oc -> output_string oc "\n");
34
Added:
assert (
35
Added:
Ogit.Resolvers.read_description_file file
36
Added:
= Ogit.Resolvers.default_repo_description);
37
Added:
Out_channel.with_open_text file (fun oc ->
38
Added:
output_string oc "A useful repository\n");
39
Added:
assert (Ogit.Resolvers.read_description_file file = "A useful repository")
40
Added:
27
41
let () =
28
42
assert (Ogit.Resolvers.is_valid_repo_name "project.git");
29
43
assert (Ogit.Resolvers.is_valid_repo_name "project");
@@ -50,4 +64,5 @@
50
64
Ogit.Resolvers.Reference.tag_name "refs/tags/v1.0.0" = Some "v1.0.0");
51
65
assert (Ogit.Resolvers.Reference.tag_name "refs/heads/v1.0.0" = None);
52
66
test_config_round_trip ();
53
Removed:
test_config_location ()
67
Added:
test_config_location ();
68
Added:
test_description_reader ()