diff --git a/base/libgit2/libgit2.jl b/base/libgit2/libgit2.jl index e6f4c97a24193..a91fe0eb7bed0 100644 --- a/base/libgit2/libgit2.jl +++ b/base/libgit2/libgit2.jl @@ -333,10 +333,12 @@ function reset!(repo::GitRepo, committish::AbstractString, pathspecs::AbstractSt # do not remove entries in the index matching the provided pathspecs with empty target commit tree obj === nothing && throw(GitError(Error.Object, Error.ERROR, "`$committish` not found")) try - reset!(repo, Nullable(obj), pathspecs...) + head = reset!(repo, Nullable(obj), pathspecs...) + return head finally close(obj) end + return head_oid(repo) end """ git reset [--soft | --mixed | --hard] """ @@ -345,10 +347,12 @@ function reset!(repo::GitRepo, commit::GitHash, mode::Cint = Consts.RESET_MIXED) # object must exist for reset obj === nothing && throw(GitError(Error.Object, Error.ERROR, "Commit `$(string(commit))` object not found")) try - reset!(repo, obj, mode) + head = reset!(repo, obj, mode) + return head finally close(obj) end + return head_oid(repo) end """ git cat-file """ @@ -513,7 +517,7 @@ function rebase!(repo::GitRepo, upstream::AbstractString="") close(head_ann) end end - return nothing + return head_oid(repo) end @@ -549,7 +553,7 @@ function snapshot(repo::GitRepo) end function restore(s::State, repo::GitRepo) - reset!(repo, Consts.HEAD_FILE, "*") # unstage everything + head = reset!(repo, Consts.HEAD_FILE, "*") # unstage everything with(GitIndex, repo) do idx read_tree!(idx, s.work) # move work tree to index opts = CheckoutOptions( diff --git a/base/libgit2/repository.jl b/base/libgit2/repository.jl index 2ef2c4482e8ed..0da122bca9569 100644 --- a/base/libgit2/repository.jl +++ b/base/libgit2/repository.jl @@ -228,6 +228,7 @@ function reset!{T<:AbstractString, S<:GitObject}(repo::GitRepo, obj::Nullable{S} repo.ptr, isnull(obj) ? C_NULL: Base.get(obj).ptr, collect(pathspecs)) + return head_oid(repo) end """Sets the current head to the specified commit oid and optionally resets the index and working tree to match.""" @@ -236,6 +237,7 @@ function reset!(repo::GitRepo, obj::GitObject, mode::Cint; @check ccall((:git_reset, :libgit2), Cint, (Ptr{Void}, Ptr{Void}, Cint, Ptr{CheckoutOptions}), repo.ptr, obj.ptr, mode, Ref(checkout_opts)) + return head_oid(repo) end function clone(repo_url::AbstractString, repo_path::AbstractString, diff --git a/test/libgit2.jl b/test/libgit2.jl index c84587deba61c..6d3a2f6728d53 100644 --- a/test/libgit2.jl +++ b/test/libgit2.jl @@ -466,8 +466,9 @@ mktempdir() do dir # because there was not any file we need to reset branch head_oid = LibGit2.head_oid(repo) - LibGit2.reset!(repo, head_oid, LibGit2.Consts.RESET_HARD) + new_head = LibGit2.reset!(repo, head_oid, LibGit2.Consts.RESET_HARD) @test isfile(joinpath(test_repo, test_file)) + @test new_head == head_oid # Detach HEAD - no merge LibGit2.checkout!(repo, string(commit_oid3)) @@ -483,8 +484,8 @@ mktempdir() do dir LibGit2.set!(cfg, "user.email", "BBBB@BBBB.COM") # Try rebasing on master instead - LibGit2.rebase!(repo, master_branch) - @test LibGit2.head_oid(repo) == head_oid + newhead = LibGit2.rebase!(repo, master_branch) + @test newhead == head_oid # Switch to the master branch LibGit2.branch!(repo, master_branch) @@ -595,14 +596,14 @@ mktempdir() do dir @test get(st_new) == get(st_stg) # try to unstage to HEAD - LibGit2.reset!(repo, LibGit2.Consts.HEAD_FILE, test_file) + new_head = LibGit2.reset!(repo, LibGit2.Consts.HEAD_FILE, test_file) st_uns = LibGit2.status(repo, test_file) @test get(st_uns) == get(st_mod) # reset repo @test_throws LibGit2.Error.GitError LibGit2.reset!(repo, LibGit2.GitHash(), LibGit2.Consts.RESET_HARD) - LibGit2.reset!(repo, LibGit2.head_oid(repo), LibGit2.Consts.RESET_HARD) + new_head = LibGit2.reset!(repo, LibGit2.head_oid(repo), LibGit2.Consts.RESET_HARD) open(joinpath(test_repo, test_file), "r") do io @test read(io)[end] != 0x41 end @@ -632,7 +633,8 @@ mktempdir() do dir LibGit2.branch!(repo, "branch/b") # squash last 2 commits - LibGit2.reset!(repo, oldhead, LibGit2.Consts.RESET_SOFT) + new_head = LibGit2.reset!(repo, oldhead, LibGit2.Consts.RESET_SOFT) + @test new_head == oldhead LibGit2.commit(repo, "squash file1 and file2") # add another file @@ -646,10 +648,10 @@ mktempdir() do dir # switch back and rebase LibGit2.branch!(repo, "branch/a") - LibGit2.rebase!(repo, "branch/b") + newnewhead = LibGit2.rebase!(repo, "branch/b") # issue #19624 - @test LibGit2.head_oid(repo) == newhead + @test newnewhead == newhead finally close(repo) end