Skip to content

Commit 9b3b2ff

Browse files
authored
Merge pull request #23438 from JuliaLang/ksh/doctransact
Add docs for transact
2 parents c301095 + b92e612 commit 9b3b2ff

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

base/libgit2/libgit2.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ function reset!(repo::GitRepo, committish::AbstractString, pathspecs::AbstractSt
522522
end
523523

524524
"""
525-
reset!(repo::GitRepo, id::GitHash, mode::Cint = Consts.RESET_MIXED)
525+
reset!(repo::GitRepo, id::GitHash, mode::Cint=Consts.RESET_MIXED)
526526
527527
Reset the repository `repo` to its state at `id`, using one of three modes
528528
set by `mode`:
@@ -861,6 +861,14 @@ function restore(s::State, repo::GitRepo)
861861
reset!(repo, s.head, Consts.RESET_SOFT) # restore head
862862
end
863863

864+
"""
865+
transact(f::Function, repo::GitRepo)
866+
867+
Apply function `f` to the git repository `repo`, taking a [`snapshot`](@ref) before
868+
applying `f`. If an error occurs within `f`, `repo` will be returned to its snapshot
869+
state using [`restore`](@ref). The error which occurred will be rethrown, but the
870+
state of `repo` will not be corrupted.
871+
"""
864872
function transact(f::Function, repo::GitRepo)
865873
state = snapshot(repo)
866874
try f(repo) catch

doc/src/devdocs/libgit2.md

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Base.LibGit2.tag_create
125125
Base.LibGit2.tag_delete
126126
Base.LibGit2.tag_list
127127
Base.LibGit2.target
128+
Base.LibGit2.transact
128129
Base.LibGit2.treewalk
129130
Base.LibGit2.upstream
130131
Base.LibGit2.update!

0 commit comments

Comments
 (0)