From 81d5366fb7c0bb8963d8df3d27054a4ad1cb6888 Mon Sep 17 00:00:00 2001 From: madmaxieee <76544194+madmaxieee@users.noreply.github.com> Date: Sun, 14 Sep 2025 21:24:34 +0800 Subject: [PATCH] feat: support alternative git host with different archive structure Some git hosting services name the directory inside their tarball archive differently. For example codeberg, unlike github, does not add the revision suffix to the direcotry in the tarball. --- lua/nvim-treesitter/install.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 29c91356c..69cfa5207 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -261,7 +261,27 @@ local function do_download(logger, url, project_name, cache_dir, revision, outpu do -- Move tmp dir to output dir local dir_rev = revision:find('^v%d') and revision:sub(2) or revision local repo_project_name = url:match('[^/]-$') - local extracted = fs.joinpath(tmp, repo_project_name .. '-' .. dir_rev) + + ---@type string? + local extracted = nil + local candidates = { + fs.joinpath(tmp, repo_project_name .. '-' .. dir_rev), + fs.joinpath(tmp, repo_project_name), + } + + for i, path in ipairs(candidates) do + if uv.fs_lstat(path) then + extracted = path + break + elseif i < #candidates then + logger:debug('Could not find extracted dir %s, trying %s...', path, candidates[i + 1]) + end + end + + if not extracted then + return logger:error('Could not find extracted dir') + end + logger:debug('Moving %s to %s/...', extracted, output_dir) local err = uv_rename(extracted, output_dir) a.schedule()