-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.ml
More file actions
30 lines (25 loc) · 1.04 KB
/
Copy pathgit.ml
File metadata and controls
30 lines (25 loc) · 1.04 KB
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
open Core.Std
(* Generate a unique dirname for a git ref *)
let generate_dirname
ref = let extract_projectname ref =
match (List.last (String.split ref ~on:'/')) with
| Some project ->
(match List.hd (String.split project ~on:'.') with
| Some project -> Some project
| _ -> Some project)
| None -> None in
let digest = String.slice (Digest.to_hex (Digest.string ref)) 0 6 in
let project = extract_projectname ref in
Option.map project ~f:(fun project -> project ^ "-" ^ digest)
let clone
~dir
ref = let pid = Unix.fork_exec ~prog: "git"
~args: ["git"; "clone"; ref; dir]
() in
Unix.waitpid_exn pid
let fetch
~dir
() = let pid = Unix.fork_exec ~prog: "git"
~args: ["git"; "-C"; dir; "fetch"; "origin"]
() in
Unix.waitpid_exn pid