Skip to content

Commit b92e612

Browse files
committed
Add docs for transact
1 parent 03c5d7d commit b92e612

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

base/libgit2/libgit2.jl

Lines changed: 9 additions & 1 deletion
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Base.LibGit2.tag_create
119119
Base.LibGit2.tag_delete
120120
Base.LibGit2.tag_list
121121
Base.LibGit2.target
122+
Base.LibGit2.transact
122123
Base.LibGit2.treewalk
123124
Base.LibGit2.upstream
124125
Base.LibGit2.update!

0 commit comments

Comments
 (0)