package b0

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Git specific operations.

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

val get_cmd : ?search:B00_std.Fpath.t list -> ?cmd:B00_std.Cmd.t -> unit -> (B00_std.Cmd.t, string) result

cmd () looks for git with Os.Cmd.get.

val find : ?dir:B00_std.Fpath.t -> unit -> (t option, string) result

find ~dir () finds, using VCS functionality, a git repository starting in directory dir (if unspecified this is the cwd).

val check_kind : t -> (unit, string) 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 B00_std.Fmt.t

pp_branch formats a branch like colorized git would.

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

pp_remote_branch formats a remote branch like colorized git would.

val remote_branch_exists : ?env:B00_std.Os.Env.assignments -> t -> remote:remote -> branch:branch -> (bool, string) result

remote_branch_exists r remote branch asserts whether branch exists on remote.

val remote_branch_fetch : ?env:B00_std.Os.Env.assignments -> ?stdout:B00_std.Os.Cmd.stdo -> ?stderr:B00_std.Os.Cmd.stdo -> t -> remote:remote -> branch:branch -> (unit, string) 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 : ?env:B00_std.Os.Env.assignments -> ?stdout:B00_std.Os.Cmd.stdo -> ?stderr:B00_std.Os.Cmd.stdo -> t -> force:bool -> src:branch -> remote:remote -> dst:remote -> (unit, string) 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 : ?env:B00_std.Os.Env.assignments -> ?stdout:B00_std.Os.Cmd.stdo -> ?stderr:B00_std.Os.Cmd.stdo -> t -> force:bool -> remote:remote -> branch:branch -> (unit, string) 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 : ?env:B00_std.Os.Env.assignments -> ?stdout:B00_std.Os.Cmd.stdo -> ?stderr:B00_std.Os.Cmd.stdo -> t -> force:bool -> branch:branch -> (unit, string) 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 : ?stdout:B00_std.Os.Cmd.stdo -> ?stderr:B00_std.Os.Cmd.stdo -> t -> force:bool -> branch:branch -> B00_std.Fpath.t -> commit_ish option -> (t, string) 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 transient_checkout_delete.

val transient_checkout_delete : ?stdout:B00_std.Os.Cmd.stdo -> ?stderr:B00_std.Os.Cmd.stdo -> t -> force:bool -> (unit, string) result

transient_checkout_delete r deletes a transient checkout. The branch created by 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 : ?stdout:B00_std.Os.Cmd.stdo -> ?stderr:B00_std.Os.Cmd.stdo -> ?dir:B00_std.Fpath.t -> t -> force:bool -> branch:branch -> commit_ish option -> (t -> 'a) -> ('a, string) result

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

Working directory

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

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

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

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

val commit : ?stdout:B00_std.Os.Cmd.stdo -> ?stderr:B00_std.Os.Cmd.stdo -> ?sign:bool -> ?reset_author:bool -> ?amend:bool -> ?msg:string -> t -> (unit, string) 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 : t -> commit_ish -> (bool, string) 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:B00_std.Os.Cmd.stdo -> ?stderr:B00_std.Os.Cmd.stdo -> t -> force:bool -> recurse:bool -> ignore_unmatch:bool -> B00_std.Fpath.t list -> (unit, string) 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.

OCaml

Innovation. Community. Security.