-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyncgitpush.ml
60 lines (56 loc) · 1.71 KB
/
syncgitpush.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(* (c) Syncgit - Lucas Baudin <[email protected]> – 2015 - see LICENSE file. *)
open Syncgitcore
open Thread
open Unix
open Lwt
let do_sync repo_state target_repository_opt =
let target_repository =
match target_repository_opt with
| Some t -> t
| None ->
begin
match repo_state.repository.name with
| Some s -> Syncgitconfig.github_user ^ "/" ^ s
| None -> raise (InvalidArgument "source http url")
end
in
match repo_state.repository.name, repo_state.repository.source_http_url with
| Some name, Some source_http_url ->
begin
print_string ("Syncing " ^ name);
let (valid, end_source_url) = is_valid_uri source_http_url in
if valid then
let project_path = Syncgitconfig.path_git ^ "/" ^ end_source_url in
begin
begin
try
begin
Unix.stat project_path;
Unix.chdir project_path;
let WEXITED i = Lwt_main.run (Lwt_process.exec ("git", [|"git";"pull";source_http_url|])) in
if i = 0 then ()
else raise UnknownGitPullError
end
with
| Unix.Unix_error(_) ->
begin
ensure_path_exist Syncgitconfig.path_git;
(* Now we can check if it has already been cloned *)
let WEXITED i = Lwt_main.run (Lwt_process.exec ("git", [|"git";"clone";source_http_url;project_path|])) in
if i = 0 then ()
else raise UnknownGitCloneError
end
end;
Unix.chdir project_path;
let WEXITED i = Lwt_main.run (Lwt_process.exec ("git", [|"git";"push";Syncgitconfig.github_url ^ target_repository;"master"|])) in
if i == 0 then
target_repository
else
raise UnknownGitPushError
end
else
raise (InvalidArgument "source http url")
end
| _ -> raise (NotEnoughArgumentsError "name, git source")
let launch_sync r =
Thread.create do_sync r