From fa4481b0ef8ff668da71d64ea41cc8d209775bee Mon Sep 17 00:00:00 2001
From: Milan Bouchet-Valat <nalimilan@club.fr>
Date: Mon, 23 Mar 2020 10:20:58 +0100
Subject: [PATCH] Bump libgit2 to 0.99.1

---
 deps/libgit2.version             |  4 ++--
 stdlib/LibGit2/src/LibGit2.jl    |  2 +-
 stdlib/LibGit2/src/blob.jl       |  2 +-
 stdlib/LibGit2/src/error.jl      | 15 ++++++++++++---
 stdlib/LibGit2/src/oid.jl        |  3 ++-
 stdlib/LibGit2/src/repository.jl |  2 +-
 stdlib/LibGit2/src/types.jl      | 11 ++++-------
 stdlib/LibGit2/src/utils.jl      |  4 ++--
 stdlib/LibGit2/src/walker.jl     |  2 +-
 stdlib/LibGit2/test/libgit2.jl   |  2 +-
 10 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/deps/libgit2.version b/deps/libgit2.version
index f67bedc41417..dc3c50c9c690 100644
--- a/deps/libgit2.version
+++ b/deps/libgit2.version
@@ -1,2 +1,2 @@
-LIBGIT2_BRANCH=v0.28.2
-LIBGIT2_SHA1=b3e1a56ebb2b9291e82dc027ba9cbcfc3ead54d3
+LIBGIT2_BRANCH=v0.99.0
+LIBGIT2_SHA1=172239021f7ba04fe7327647b213799853a9eb89
diff --git a/stdlib/LibGit2/src/LibGit2.jl b/stdlib/LibGit2/src/LibGit2.jl
index 627922e138a5..b890a0c42f74 100644
--- a/stdlib/LibGit2/src/LibGit2.jl
+++ b/stdlib/LibGit2/src/LibGit2.jl
@@ -18,10 +18,10 @@ const REFCOUNT = Threads.Atomic{Int}(0)
 
 function ensure_initialized end
 
+include("error.jl")
 include("utils.jl")
 include("consts.jl")
 include("types.jl")
-include("error.jl")
 include("signature.jl")
 include("oid.jl")
 include("reference.jl")
diff --git a/stdlib/LibGit2/src/blob.jl b/stdlib/LibGit2/src/blob.jl
index b416fac7329e..efd7a14c9c6f 100644
--- a/stdlib/LibGit2/src/blob.jl
+++ b/stdlib/LibGit2/src/blob.jl
@@ -67,7 +67,7 @@ id = LibGit2.addblob!(repo, blob_file)
 function addblob!(repo::GitRepo, path::AbstractString)
     ensure_initialized()
     id_ref = Ref{GitHash}()
-    @check ccall((:git_blob_create_fromdisk, :libgit2), Cint,
+    @check ccall((:git_blob_create_from_disk, :libgit2), Cint,
                  (Ptr{GitHash}, Ptr{Cvoid}, Cstring),
                  id_ref, repo.ptr, path)
     return id_ref[]
diff --git a/stdlib/LibGit2/src/error.jl b/stdlib/LibGit2/src/error.jl
index 4d1e915cef31..3e56999d5a52 100644
--- a/stdlib/LibGit2/src/error.jl
+++ b/stdlib/LibGit2/src/error.jl
@@ -25,9 +25,13 @@ export GitError
             ECERTIFICATE    = Cint(-17), # server certificate is invalid
             EAPPLIED        = Cint(-18), # patch/merge has already been applied
             EPEEL           = Cint(-19), # the requested peel operation is not possible
-            EEOF            = Cint(-20), # Unexpted EOF
+            EEOF            = Cint(-20), # unexpected EOF
             PASSTHROUGH     = Cint(-30), # internal only
-            ITEROVER        = Cint(-31)) # signals end of iteration
+            ITEROVER        = Cint(-31), # signals end of iteration
+            RETRY           = Cint(-32), # internal only
+            EMISMATCH       = Cint(-33), # hashsum mismatch in object
+            EINDEXDIRTY     = Cint(-34), # unsaved changes in the index would be overwritten
+            EAPPLYFAIL      = Cint(-35)) # patch application failed
 
 @enum(Class, None,
              NoMemory,
@@ -58,7 +62,12 @@ export GitError
              Callback,
              CherryPick,
              Describe,
-             Rebase)
+             Rebase,
+             Filesystem,
+             Patch,
+             WorkTree,
+             SHA1,
+             HTTP)
 
 struct ErrorStruct
     message::Ptr{UInt8}
diff --git a/stdlib/LibGit2/src/oid.jl b/stdlib/LibGit2/src/oid.jl
index 069d725685a6..1074f003ebd2 100644
--- a/stdlib/LibGit2/src/oid.jl
+++ b/stdlib/LibGit2/src/oid.jl
@@ -13,7 +13,8 @@ function GitHash(ptr::Ptr{UInt8})
     end
     ensure_initialized()
     oid_ptr = Ref(GitHash())
-    ccall((:git_oid_fromraw, :libgit2), Cvoid, (Ptr{GitHash}, Ptr{UInt8}), oid_ptr, ptr)
+    @check ccall((:git_oid_fromraw, :libgit2), Cint,
+                 (Ptr{GitHash}, Ptr{UInt8}), oid_ptr, ptr)
     return oid_ptr[]
 end
 
diff --git a/stdlib/LibGit2/src/repository.jl b/stdlib/LibGit2/src/repository.jl
index 96249bd9f69d..8c858b1f8f90 100644
--- a/stdlib/LibGit2/src/repository.jl
+++ b/stdlib/LibGit2/src/repository.jl
@@ -32,7 +32,7 @@ end
 function cleanup(r::GitRepo)
     if r.ptr != C_NULL
         ensure_initialized()
-        ccall((:git_repository__cleanup, :libgit2), Cvoid, (Ptr{Cvoid},), r.ptr)
+        @check ccall((:git_repository__cleanup, :libgit2), Cint, (Ptr{Cvoid},), r.ptr)
     end
 end
 
diff --git a/stdlib/LibGit2/src/types.jl b/stdlib/LibGit2/src/types.jl
index 6ffbe67ea277..3edb76a73dac 100644
--- a/stdlib/LibGit2/src/types.jl
+++ b/stdlib/LibGit2/src/types.jl
@@ -197,7 +197,7 @@ end
     LibGit2.TransferProgress
 
 Transfer progress information used by the `transfer_progress` remote callback.
-Matches the [`git_transfer_progress`](https://libgit2.org/libgit2/#HEAD/type/git_transfer_progress) struct.
+Matches the [`git_indexer_progress`](https://libgit2.org/libgit2/#HEAD/type/git_indexer_progress) struct.
 """
 @kwdef struct TransferProgress
     total_objects::Cuint    = Cuint(0)
@@ -223,6 +223,7 @@ end
     push_negotiation::Ptr{Cvoid}       = C_NULL
     transport::Ptr{Cvoid}              = C_NULL
     payload::Ptr{Cvoid}                = C_NULL
+    resolve_url::Ptr{Cvoid}            = C_NULL
 end
 
 """
@@ -325,12 +326,8 @@ end
     prune::Cint                        = Consts.FETCH_PRUNE_UNSPECIFIED
     update_fetchhead::Cint             = Cint(1)
     download_tags::Cint                = Consts.REMOTE_DOWNLOAD_TAGS_AUTO
-    @static if LibGit2.VERSION >= v"0.25.0"
-        proxy_opts::ProxyOptions       = ProxyOptions()
-    end
-    @static if LibGit2.VERSION >= v"0.24.0"
-        custom_headers::StrArrayStruct = StrArrayStruct()
-    end
+    proxy_opts::ProxyOptions           = ProxyOptions()
+    custom_headers::StrArrayStruct     = StrArrayStruct()
 end
 
 """
diff --git a/stdlib/LibGit2/src/utils.jl b/stdlib/LibGit2/src/utils.jl
index 147b0949f74c..b601ea4efe60 100644
--- a/stdlib/LibGit2/src/utils.jl
+++ b/stdlib/LibGit2/src/utils.jl
@@ -37,8 +37,8 @@ function version()
     major = Ref{Cint}(0)
     minor = Ref{Cint}(0)
     patch = Ref{Cint}(0)
-    ccall((:git_libgit2_version, :libgit2), Cvoid,
-          (Ref{Cint}, Ref{Cint}, Ref{Cint}), major, minor, patch)
+    @check ccall((:git_libgit2_version, :libgit2), Cint,
+                 (Ref{Cint}, Ref{Cint}, Ref{Cint}), major, minor, patch)
     return VersionNumber(major[], minor[], patch[])
 end
 const VERSION = version()
diff --git a/stdlib/LibGit2/src/walker.jl b/stdlib/LibGit2/src/walker.jl
index 1d2fbcb52f9b..e977590eafb8 100644
--- a/stdlib/LibGit2/src/walker.jl
+++ b/stdlib/LibGit2/src/walker.jl
@@ -77,7 +77,7 @@ end
 function Base.sort!(w::GitRevWalker; by::Cint = Consts.SORT_NONE, rev::Bool=false)
     ensure_initialized()
     rev && (by |= Consts.SORT_REVERSE)
-    ccall((:git_revwalk_sorting, :libgit2), Cvoid, (Ptr{Cvoid}, Cint), w.ptr, by)
+    @check ccall((:git_revwalk_sorting, :libgit2), Cint, (Ptr{Cvoid}, Cint), w.ptr, by)
     return w
 end
 
diff --git a/stdlib/LibGit2/test/libgit2.jl b/stdlib/LibGit2/test/libgit2.jl
index b7ecd31d5f0a..c1418f5ad6fb 100644
--- a/stdlib/LibGit2/test/libgit2.jl
+++ b/stdlib/LibGit2/test/libgit2.jl
@@ -3043,7 +3043,7 @@ mktempdir() do dir
                             deserialize(f)
                         end
                         @test err.code == LibGit2.Error.ERROR
-                        @test lowercase(err.msg) == lowercase("invalid Content-Type: text/plain")
+                        @test lowercase(err.msg) == lowercase("invalid Content-Type: 'text/plain'")
                     end
 
                     # OpenSSL s_server should still be running
