Skip to content

Commit

Permalink
Adjust Git_kv.commit to report staging status
Browse files Browse the repository at this point in the history
The implementation is a bit too naïve and will report the commit dirty
even when there are no staged changes. It only detects if we're inside a
`change_and_push`.
  • Loading branch information
reynir committed Nov 28, 2024
1 parent 60795e6 commit 3276c90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/git_kv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ let connect ctx endpoint =

let branch t = t.branch

let commit t = t.head
let commit t =
match t.head, t.committed with
| None, _ -> None
| Some commit, None -> Some (`Clean commit)
| Some commit, Some _ ->
(* XXX: this is not precise as we can have made zero changes *)
Some (`Dirty commit)

type key = Mirage_kv.Key.t

Expand Down
6 changes: 4 additions & 2 deletions src/git_kv.mli
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ val connect : Mimic.ctx -> string -> t Lwt.t
val branch : t -> Git.Reference.t
(** [branch t] returns the branch used by the given [t]. *)

val commit : t -> Digestif.SHA1.t option
(** [commit t] returns the commit used by the given [t]. *)
val commit : t -> [ `Clean of Digestif.SHA1.t | `Dirty of Digestif.SHA1.t ] option
(** [commit t] returns the commit used by the given [t]. The commit is either
marked [`Dirty _] if we're inside a [change_and_push] or [`Clean _]
otherwise. *)

val to_octets : ?level:int -> t -> string Lwt_stream.t
(** [to_octets ?level store] returns a serialized version of the given [store].
Expand Down

0 comments on commit 3276c90

Please sign in to comment.