B0_vcs_repo.Git
Git specific operations.
All the following operations assume the repository is of kind Git
. Use the repository lookup functions of this module or Git.check_kind
to assert this first otherwise the operations will fail in non-user friendly ways.
val get_cmd :
?search:B0_std.Cmd.tool_search ->
?cmd:B0_std.Cmd.t ->
unit ->
(B0_std.Cmd.t, string) Stdlib.result
cmd ()
looks for git
with Os.Cmd.get ?search
.
val find :
?search:B0_std.Cmd.tool_search ->
?dir:B0_std.Fpath.t ->
unit ->
(t option, string) Stdlib.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) Stdlib.result
check_kind r
is Ok ()
if r
's kind is Git
and errors otherwise.
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 :
?env:B0_std.Os.Env.assignments ->
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 :
?env:B0_std.Os.Env.assignments ->
?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
fetches branch
of remote
. stderr
and stdout
indicates where they should be redirected, defaults to the values of B0_std.Os.Cmd.run_status
.
val remote_branch_push :
?env:B0_std.Os.Env.assignments ->
?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 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 B0_std.Os.Cmd.run_status
.
val remote_branch_delete :
?env:B0_std.Os.Env.assignments ->
?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
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 B0_std.Os.Cmd.run_status
.
val branch_delete :
?env:B0_std.Os.Env.assignments ->
?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
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 B0_std.Os.Cmd.run_status
.
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:B0_std.Os.Cmd.stdo ->
?stderr:B0_std.Os.Cmd.stdo ->
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 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:B0_std.Os.Cmd.stdo ->
?stderr:B0_std.Os.Cmd.stdo ->
t ->
force:bool ->
(unit, string) Stdlib.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:B0_std.Os.Cmd.stdo ->
?stderr:B0_std.Os.Cmd.stdo ->
?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
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 B0_std.Os.Path.tmp
.
val add :
?stdout:B0_std.Os.Cmd.stdo ->
?stderr:B0_std.Os.Cmd.stdo ->
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 .gitignore
s.
val has_staged_changes : t -> (bool, string) Stdlib.result
has_staged_changes r
is true
if r
has staged changes that can be commit
ed 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 ->
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 B0_std.Os.Cmd.run_status
.
val commit_exists : t -> 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 ->
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 B0_std.Os.Cmd.run_status
.