Module B0_vcs.Git

module Git: sig .. end

Git specific operations.

All the following operations assume the repository is of kind Git. Use B0_vcs.Git.check_kind to assert this first otherwise the operations will fail in a non-user friendly way.


val check_kind : B0_vcs.t -> (unit, string) Stdlib.result

check_kind r is Ok () if r's kind is Git and errors otherwise.

Branches

type remote = string 

The type for remote identifiers.

type branch = string 

The type for branch identifiers.

val pp_branch : branch B0_std.Fmt.t

pp_branch formats a branch like colorized git would.

val pp_remote_branch : (remote * branch) B0_std.Fmt.t

pp_remote_branch formats a remote branch like colorized git would.

val remote_branch_exists : B0_vcs.t ->
remote:remote ->
branch:branch -> (bool, string) Stdlib.result

remote_branch_exists r remote branch asserts whether branch exists on remote.

val remote_branch_fetch : ?stdout:B0_std.Os.Cmd.stdo ->
?stderr:B0_std.Os.Cmd.stdo ->
B0_vcs.t ->
remote:remote ->
branch:branch -> (unit, string) Stdlib.result

remote_branch_fetch r remote branch fetches branch of remote. stderr and stdout indicates where they should be redirected, defaults to the values of Os.Cmd.run_status.

val remote_branch_push : ?stdout:B0_std.Os.Cmd.stdo ->
?stderr:B0_std.Os.Cmd.stdo ->
B0_vcs.t ->
force:bool ->
src:branch ->
remote:remote ->
dst:remote -> (unit, string) Stdlib.result

remote_branch_push r ~force ~local ~remote ~dst pushes branch src on dst of remote. If dst does not exist on remote a new branch is created. If force is true this is a forced update. stderr and stdout indicates where they should be redirected, defaults to the values of Os.Cmd.run_status.

val remote_branch_delete : ?stdout:B0_std.Os.Cmd.stdo ->
?stderr:B0_std.Os.Cmd.stdo ->
B0_vcs.t ->
force:bool ->
remote:remote ->
branch:branch -> (unit, string) Stdlib.result

remote_branch_delete r ~remote ~branch deletes branch on remote. If force is true this is a forced update. stderr and stdout indicates where they should be redirected, defaults to the values of Os.Cmd.run_status.

val branch_delete : ?stdout:B0_std.Os.Cmd.stdo ->
?stderr:B0_std.Os.Cmd.stdo ->
B0_vcs.t ->
force:bool -> branch:branch -> (unit, string) Stdlib.result

branch_delete r ~force ~branch deletes branch in r. If force is true this is a forced deletion. stderr and stdout indicates where they should be redirected, defaults to the values of Os.Cmd.run_status.

Transient checkouts

The following functions use git worktree to programmatically act on repo branches without disturbing the user's checkout and/or needing to clone the repo. Use them for short-lived operations that need a work tree and then delete them. The branch that was created can the be pushed on other branches and then deleted.

val transient_checkout : B0_vcs.t ->
force:bool ->
branch:branch ->
B0_std.Fpath.t ->
B0_vcs.commit_ish option -> (B0_vcs.t, string) Stdlib.result

checkout_tmp_branch r ~force ~branch dir commit_ish creates and checkouts and a branch branch in dir that points to commit_ish (if None an empty orphan branch is created). Unless force is true this fails if branch already exists. The resulting repo should be used to interact with the checkout. Once finished it should be disposed with B0_vcs.Git.transient_checkout_delete.

val transient_checkout_delete : B0_vcs.t -> force:bool -> (unit, string) Stdlib.result

transient_checkout_delete r deletes a transient checkout. The branch created by B0_vcs.Git.transient_checkout is not deleted by the operation, only the corresponding working tree. If force will delete even if the checkout is dirty.

val with_transient_checkout : ?dir:B0_std.Fpath.t ->
B0_vcs.t ->
force:bool ->
branch:branch ->
B0_vcs.commit_ish option -> (B0_vcs.t -> 'a) -> ('a, string) Stdlib.result

with_transient_checkout r ~force ~branch ~dir commit_ish f calls B0_vcs.Git.transient_checkout and then f r with r the repo to act on the checkout. Once f r returns normally or via an exception B0_vcs.Git.transient_checkout_delete is called. dir defaults to a temporary directory given by B0_std.Os.Path.tmp.

Working directory

val add : B0_vcs.t -> force:bool -> B0_std.Fpath.t list -> (unit, string) Stdlib.result

add t ~force fs adds fs to r's staged changes. If force bypasses the .gitignores.

val has_staged_changes : B0_vcs.t -> (bool, string) Stdlib.result

has_staged_changes r is true if r has staged changes that can be B0_vcs.Git.commited and false otherwise.

val commit : ?stdout:B0_std.Os.Cmd.stdo ->
?stderr:B0_std.Os.Cmd.stdo ->
?sign:bool ->
?reset_author:bool ->
?amend:bool -> ?msg:string -> B0_vcs.t -> (unit, string) Stdlib.result

commit r ~sign ~msg ~ammend ~reset_author is basically git commit, see git-commit(1) for the semantics of options. stderr and stdout indicates where they should be redirected, defaults to the values of Os.Cmd.run_status.

val commit_exists : B0_vcs.t -> B0_vcs.commit_ish -> (bool, string) Stdlib.result

commit_exists r cish checks whether cish exists in r. In particular using this with HEAD allows to know if a commit exists in the branch checkout.

val rm : ?stdout:B0_std.Os.Cmd.stdo ->
?stderr:B0_std.Os.Cmd.stdo ->
B0_vcs.t ->
force:bool ->
recurse:bool ->
ignore_unmatch:bool -> B0_std.Fpath.t list -> (unit, string) Stdlib.result

rm r ~force ~recurse ~ignore_unmatch files removes files from the working tree and from the index. if force removes the files even if they are not up-to-date. If recurse removes directories recursively if true. If ignore_unmatch does not error if elements of files do not match files. stderr and stdout indicates where they should be redirected, defaults to the values of Os.Cmd.run_status.