From 4cab526ca2481daf849b6cf59338fc0db699f70f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:34:33 +0000 Subject: [PATCH 1/2] Initial plan From ebd10b188aab1e810014d98d30975bfff0f21bfa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 14 Oct 2026 14:35:53 +0000 Subject: [PATCH 2/2] Apply remaining changes Co-authored-by: alt-graph <28754274+alt-graph@users.noreply.github.com> --- include/libgit4cpp/Remote.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/libgit4cpp/Remote.h b/include/libgit4cpp/Remote.h index 8947c23..64b0293 100644 --- a/include/libgit4cpp/Remote.h +++ b/include/libgit4cpp/Remote.h @@ -72,6 +72,19 @@ class Remote std::vector list_references(); private: + // Keeps libgit2 initialized for as long as the remote exists, because the remote may + // outlive its Repository. Declared before remote_ so that it is destroyed after it. + struct LibGitInitGuard + { + LibGitInitGuard() { git_libgit2_init(); } + LibGitInitGuard(LibGitInitGuard&&) { git_libgit2_init(); } + LibGitInitGuard(const LibGitInitGuard&) = delete; + LibGitInitGuard& operator=(LibGitInitGuard&&) = default; + LibGitInitGuard& operator=(const LibGitInitGuard&) = delete; + ~LibGitInitGuard() { git_libgit2_shutdown(); } + }; + + LibGitInitGuard init_guard_; LibGitRemote remote_{ nullptr, git_remote_free }; };