Skip to content

Commit 9731d45

Browse files
committed
Add an example in the README
1 parent 800bc76 commit 9731d45

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,37 @@ $ opam install git
7979

8080
Performance is comparable to the Git tool.
8181

82+
### Example
83+
84+
```ocaml
85+
# require "git.unix";;
86+
# open Lwt.Infix;;
87+
# open Git_unix;;
88+
# module Search = Git.Search(FS);;
89+
90+
# let read file =
91+
FS.create () >>= fun t ->
92+
FS.read_reference_exn t Git.Reference.master >>= fun head ->
93+
Search.find t (Git.SHA.of_commit head) (`Commit (`Path file)) >>= function
94+
| None -> failwith "file not found"
95+
| Some sha -> FS.read_exn t sha >>= function
96+
| Git.Value.Blob b -> Lwt.return (Git.Blob.to_raw b)
97+
| _ -> failwith "not a valid path"
98+
;;
99+
val read : string list -> string Lwt.t = <fun>
100+
101+
# Lwt_main.run (read ["README.md"] >|= print_string)
102+
103+
Pure OCaml low-level bindings to Git -- Guaranteed no C inside.
104+
105+
Support for on-disk and in-memory Git stores. Can read and write all
106+
the Git objects: the usual blobs, trees, commits and tags but also
107+
the pack files, pack indexes and the index file (where the staging area
108+
lives).
109+
110+
[...]
111+
```
112+
82113
### License
83114

84115
MIT, see LICENSE file for its text.

0 commit comments

Comments
 (0)