forked from
gazagnaire.org/irmin
Persistent store with Git semantics: lazy reads, delayed writes, content-addressing
1(** Set command. *)
2
3let run ~repo ~branch ~message path content =
4 let content =
5 match content with Some c -> c | None -> In_channel.(input_all stdin)
6 in
7 let message = match message with Some m -> m | None -> "Set " ^ path in
8 let config = Config.load ~repo () in
9 let (module B : Common.BACKEND) = Common.backend_of_config config in
10 Eio_main.run @@ fun env ->
11 let fs = Eio.Stdenv.cwd env in
12 Eio.Switch.run @@ fun sw ->
13 let store = B.open_store ~sw ~fs ~config in
14 let tree =
15 match B.checkout store ~branch with
16 | None -> B.empty_tree store
17 | Some t -> t
18 in
19 let tree = B.tree_add tree (Common.path_of_string path) content in
20 let parents =
21 match B.head store ~branch with None -> [] | Some h -> [ h ]
22 in
23 let hash =
24 B.commit store ~tree ~parents ~message ~author:"irmin <irmin@local>"
25 in
26 B.set_head store ~branch hash;
27 Common.success "%a" Common.styled_faint (B.hash_short hash)