From 3276c90b0830fc8266eeae995c8f7272e4d329fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Thu, 28 Nov 2024 12:33:49 +0100 Subject: [PATCH] Adjust Git_kv.commit to report staging status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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`. --- src/git_kv.ml | 8 +++++++- src/git_kv.mli | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/git_kv.ml b/src/git_kv.ml index 61d6197..2fea998 100644 --- a/src/git_kv.ml +++ b/src/git_kv.ml @@ -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 diff --git a/src/git_kv.mli b/src/git_kv.mli index 3de53d7..735e12e 100644 --- a/src/git_kv.mli +++ b/src/git_kv.mli @@ -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].