use locked revision when downloading via git

This commit is contained in:
AdnoC 2021-01-04 13:28:26 -05:00 committed by Thomas Vigouroux
parent 234557b95e
commit 4d2813f03b

View file

@ -125,11 +125,12 @@ function M.select_download_commands(repo, project_name, cache_folder, revision)
local has_curl = vim.fn.executable('curl') == 1
local is_github = repo.url:find("github.com", 1, true)
local is_gitlab = repo.url:find("gitlab.com", 1, true)
local is_windows = fn.hs('win32')
local is_windows = fn.has('win32') == 1
revision = revision or repo.branch or "master"
if has_tar and has_curl and (is_github or is_gitlab) and not is_windows then
revision = revision or repo.branch or "master"
local path_sep = utils.get_path_sep()
local url = repo.url:gsub('.git$', '')
@ -172,22 +173,46 @@ function M.select_download_commands(repo, project_name, cache_folder, revision)
M.select_install_rm_cmd(cache_folder, project_name..'-tmp')
}
else
local git_folder
if is_windows then
git_folder = cache_folder ..'\\'.. project_name
else
git_folder = cache_folder ..'/'.. project_name
end
local clone_error = 'Error during download, please verify your internet connection'
if is_windows then
clone_error = clone_error .. ". If on Windows you may need to enable Developer mode"
end
return {
{
cmd = 'git',
info = 'Downloading...',
err = 'Error during download, please verify your internet connection',
err = clone_error,
opts = {
args = {
'clone',
'-c', 'core.symlinks=true',
'--single-branch',
'--branch', repo.branch or 'master',
'--depth', '1',
repo.url,
project_name
},
cwd = cache_folder,
},
},
{
cmd = 'git',
info = 'Checking out locked revision',
err = 'Error while checking out revision',
opts = {
args = {
'-c', 'core.symlinks=true',
'checkout', revision
},
cwd = git_folder
}
}
}
end