-
Notifications
You must be signed in to change notification settings - Fork 157
/
sync.ml
43 lines (37 loc) · 1.67 KB
/
sync.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
(*
* Copyright (c) 2013-2022 Thomas Gazagnaire <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)
open Lwt.Syntax
let () = Mirage_crypto_rng_unix.initialize (module Mirage_crypto_rng.Fortuna)
let info = Irmin_git_unix.info
let path =
if Array.length Sys.argv = 2 then Sys.argv.(1)
else "git://github.com/mirage/ocaml-git.git"
module Store = Irmin_git_unix.FS.KV (Irmin.Contents.String)
module Sync = Irmin.Sync.Make (Store)
let test () =
Config.init ();
let config = Irmin_git.config Config.root in
let* repo = Store.Repo.v config in
let* t = Store.of_branch repo "master" in
let* upstream = Store.remote path in
let* _ = Sync.pull_exn t upstream `Set in
let* readme = Store.get t [ "README.md" ] in
let* tree = Store.get_tree t [] in
let* tree = Store.Tree.add tree [ "BAR.md" ] "Hoho!" in
let* tree = Store.Tree.add tree [ "FOO.md" ] "Hihi!" in
let+ () = Store.set_tree_exn t ~info:(info "merge") [] tree in
Printf.printf "%s\n%!" readme
let () = Lwt_main.run (test ())