Skip to content

Commit

Permalink
Added in fallback to fetch everything if we can't find a specific obj…
Browse files Browse the repository at this point in the history
…ect.
  • Loading branch information
adamharrison committed Jun 9, 2024
1 parent 259331a commit 6e33089
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,12 @@ static int lpm_fetch(lua_State* L) {
git_repository_free(repository);
return luaL_error(L, "git remote fetch error: %s", git_error_last_string());
}
const char* refspec = lua_gettop(L) >= 3 ? luaL_checkstring(L, 3) : NULL;
const char* refspec = luaL_optstring(L, 3, NULL);
git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT;
fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL;
fetch_opts.callbacks.payload = L;
#if (LIBGIT2_VER_MAJOR == 1 && LIBGIT2_VER_MINOR >= 7) || LIBGIT2_VER_MAJOR > 1
fetch_opts.depth = 1;
fetch_opts.depth = lua_toboolean(L, 4) ? GIT_FETCH_DEPTH_FULL : 1;
#endif
if (no_verify_ssl)
fetch_opts.callbacks.certificate_check = lpm_git_transport_certificate_check_cb;
Expand Down
9 changes: 5 additions & 4 deletions src/lpm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1262,10 +1262,11 @@ function Repository:fetch()
end
if not exists or self.branch then
log.progress_action("Fetching " .. self.remote .. ":" .. (self.commit or self.branch) .. "...")
if self.commit then
system.fetch(temporary_path or path, write_progress_bar, self.commit)
elseif self.branch then
system.fetch(temporary_path or path, write_progress_bar, "+refs/heads/" .. self.branch .. ":refs/remotes/origin/" .. self.branch)
local status, err = pcall(system.fetch, temporary_path or path, write_progress_bar, self.commit or ("+refs/heads/" .. self.branch .. ":refs/remotes/origin/" .. self.branch))
if not status and err:find("cannot fetch a specific object") then
system.fetch(temporary_path or path, write_progress_bar, nil, true)
elseif not status then
error(err, 0)
end
common.reset(temporary_path or path, self.commit or self.branch, "hard")
end
Expand Down

0 comments on commit 6e33089

Please sign in to comment.