@@ -35,7 +35,7 @@ void git_references::sort() noexcept
3535 return it;
3636 }
3737
38- if (auto const it = find_ref (std::format (" ref /tags/{}" , name)); it != end ()) {
38+ if (auto const it = find_ref (std::format (" refs /tags/{}" , name)); it != end ()) {
3939 return it;
4040 }
4141
@@ -158,17 +158,18 @@ class git_lib {
158158 if (auto const r = ::git_remote_create_anonymous (&remote, nullptr , url.c_str ()); r != GIT_OK) {
159159 return std::unexpected{make_git_error (r)};
160160 }
161+ auto const d1 = defer{[&] {
162+ ::git_remote_free (remote);
163+ }};
161164
162165 if (auto const r = ::git_remote_connect (remote, GIT_DIRECTION_FETCH, nullptr , nullptr , nullptr ); r != GIT_OK) {
163- ::git_remote_free (remote);
164166 return std::unexpected{make_git_error (r)};
165167 }
166168
167169 ::git_remote_head const ** list_head = nullptr ;
168170 size_t list_size = 0 ;
169171
170172 if (auto const r = ::git_remote_ls (&list_head, &list_size, remote); r != GIT_OK) {
171- ::git_remote_free (remote);
172173 return std::unexpected{make_git_error (r)};
173174 }
174175
@@ -187,7 +188,6 @@ class git_lib {
187188 r.emplace_back (std::move (name), std::move (oid_str));
188189 }
189190
190- ::git_remote_free (remote);
191191 r.sort ();
192192 return r;
193193}
@@ -315,7 +315,7 @@ repository_fetch(::git_repository* repository, std::string const& remote_name =
315315 if (auto result = ::git_remote_lookup (&remote, repository, remote_name.c_str ()); result != GIT_OK) {
316316 return make_git_error (result);
317317 }
318- defer{[&] {
318+ auto const d1 = defer{[&] {
319319 ::git_remote_free (remote);
320320 }};
321321
@@ -532,7 +532,7 @@ git_fetch_and_update(std::string const& url, std::string const& rev, std::filesy
532532 return git_error::ok;
533533}
534534
535- [[nodiscard]] git_error git_clone (std::string const & url, std::string const & branch , std::filesystem::path path)
535+ [[nodiscard]] git_error git_clone (std::string const & url, std::string const & git_rev , std::filesystem::path path)
536536{
537537 auto const & _ = git_lib_initialize ();
538538
@@ -550,10 +550,10 @@ git_fetch_and_update(std::string const& url, std::string const& rev, std::filesy
550550 return make_git_error (r);
551551 }
552552
553- auto branch_it = ref_list.find (branch );
553+ auto branch_it = ref_list.find (git_rev );
554554 if (branch_it != ref_list.end ()) {
555555 if (branch_it->is_branch ()) {
556- options.checkout_branch = branch .c_str ();
556+ options.checkout_branch = git_rev .c_str ();
557557 options.fetch_opts .depth = 1 ;
558558 force_checkout = true ;
559559
@@ -572,6 +572,9 @@ git_fetch_and_update(std::string const& url, std::string const& rev, std::filesy
572572 if (auto r = ::git_clone (&repository, url.c_str (), path.string ().c_str (), &options); r != GIT_OK) {
573573 return make_git_error (r);
574574 }
575+ auto d1 = defer{[&] { ::git_repository_free (repository); }};
576+
577+ return git_error::ok;
575578}
576579
577580// [[nodiscard]] git_error git_checkout_or_clone(
0 commit comments