Module B0_vcs.Git
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 check_kind : t -> (unit, string) Stdlib.result
check_kind r
isOk ()
ifr
's kind isGit
and errors otherwise.
Branches
val pp_branch : branch B0_std.Fmt.t
pp_branch
formats a branch like colorizedgit
would.
val pp_remote_branch : (remote * branch) B0_std.Fmt.t
pp_remote_branch
formats a remote branch like colorizedgit
would.
val remote_branch_exists : t -> remote:remote -> branch:branch -> (bool, string) Stdlib.result
remote_branch_exists r remote branch
asserts whetherbranch
exists onremote
.
val remote_branch_fetch : ?stdout:B0_std.Os.Cmd.stdo -> ?stderr:B0_std.Os.Cmd.stdo -> t -> remote:remote -> branch:branch -> (unit, string) Stdlib.result
remote_branch_fetch r remote branch
fetchesbranch
ofremote
.stderr
andstdout
indicates where they should be redirected, defaults to the values ofOs
.Cmd.run_status.
val remote_branch_push : ?stdout:B0_std.Os.Cmd.stdo -> ?stderr:B0_std.Os.Cmd.stdo -> t -> force:bool -> src:branch -> remote:remote -> dst:remote -> (unit, string) Stdlib.result
remote_branch_push r ~force ~local ~remote ~dst
pushes branchsrc
ondst
ofremote
. Ifdst
does not exist onremote
a new branch is created. Ifforce
istrue
this is a forced update.stderr
andstdout
indicates where they should be redirected, defaults to the values ofOs
.Cmd.run_status.
val remote_branch_delete : ?stdout:B0_std.Os.Cmd.stdo -> ?stderr:B0_std.Os.Cmd.stdo -> t -> force:bool -> remote:remote -> branch:branch -> (unit, string) Stdlib.result
remote_branch_delete r ~remote ~branch
deletesbranch
onremote
. Ifforce
istrue
this is a forced update.stderr
andstdout
indicates where they should be redirected, defaults to the values ofOs
.Cmd.run_status.
val branch_delete : ?stdout:B0_std.Os.Cmd.stdo -> ?stderr:B0_std.Os.Cmd.stdo -> t -> force:bool -> branch:branch -> (unit, string) Stdlib.result
branch_delete r ~force ~branch
deletesbranch
inr
. Ifforce
istrue
this is a forced deletion.stderr
andstdout
indicates where they should be redirected, defaults to the values ofOs
.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 : t -> force:bool -> branch:branch -> B0_std.Fpath.t -> commit_ish option -> (t, string) Stdlib.result
checkout_tmp_branch r ~force ~branch dir commit_ish
creates and checkouts and a branchbranch
indir
that points tocommit_ish
(ifNone
an empty orphan branch is created). Unlessforce
istrue
this fails ifbranch
already exists. The resulting repo should be used to interact with the checkout. Once finished it should be disposed withtransient_checkout_delete
.
val transient_checkout_delete : t -> force:bool -> (unit, string) Stdlib.result
transient_checkout_delete r
deletes a transient checkout. The branch created bytransient_checkout
is not deleted by the operation, only the corresponding working tree. Ifforce
will delete even if the checkout is dirty.
val with_transient_checkout : ?dir:B0_std.Fpath.t -> t -> force:bool -> branch:branch -> commit_ish option -> (t -> 'a) -> ('a, string) Stdlib.result
with_transient_checkout r ~force ~branch ~dir commit_ish f
callstransient_checkout
and thenf r
withr
the repo to act on the checkout. Oncef r
returns normally or via an exceptiontransient_checkout_delete
is called.dir
defaults to a temporary directory given byB0_std.Os.Path.tmp
.
Working directory
val add : t -> force:bool -> B0_std.Fpath.t list -> (unit, string) Stdlib.result
add t ~force fs
addsfs
tor
's staged changes. Ifforce
bypasses the.gitignore
s.
val has_staged_changes : t -> (bool, string) Stdlib.result
has_staged_changes r
istrue
ifr
has staged changes that can becommit
ed andfalse
otherwise.
val commit : ?stdout:B0_std.Os.Cmd.stdo -> ?stderr:B0_std.Os.Cmd.stdo -> ?sign:bool -> ?reset_author:bool -> ?amend:bool -> ?msg:string -> t -> (unit, string) Stdlib.result
commit r ~sign ~msg ~ammend ~reset_author
is basicallygit commit
, seegit-commit(1)
for the semantics of options.stderr
andstdout
indicates where they should be redirected, defaults to the values ofOs
.Cmd.run_status.
val commit_exists : t -> commit_ish -> (bool, string) Stdlib.result
commit_exists r cish
checks whethercish
exists inr
. In particular using this withHEAD
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 -> t -> force:bool -> recurse:bool -> ignore_unmatch:bool -> B0_std.Fpath.t list -> (unit, string) Stdlib.result
rm r ~force ~recurse ~ignore_unmatch files
removesfiles
from the working tree and from the index. ifforce
removes the files even if they are not up-to-date. Ifrecurse
removes directories recursively iftrue
. Ifignore_unmatch
does not error if elements offiles
do not match files.stderr
andstdout
indicates where they should be redirected, defaults to the values ofOs
.Cmd.run_status.