Repository: neovim/neovim
File: runtime/lua/vim/health/health.lua (Lua)

Code before:
  return 'unknown'
end

---@param nvim_version string
local function check_stable_version(nvim_version)
  local latest_version = nil
  if vim.fn.executable('git') == 1 then
    local result = vim
      .system({
        'git',
        'ls-remote',
        '--tags',
        'https://github.com/neovim/neovim',
      }, { text = true })
      :wait()
    local stable_sha = result.stdout:match('(%x+)%s+refs/tags/stable\n')
    if stable_sha then
      latest_version = result.stdout:match(stable_sha .. '%s+refs/tags/v?(%d+%.%d+%.%d+)%^{}')
    end
  end

  if latest_version then
    local current_version = nvim_version:match('v(%d+%.%d+%.%d+)')
    if latest_version ~= current_version then
      vim.health.warn(
        string.format('Neovim %s is available (current: %s)', latest_version, current_version)
      )
    end
  end
end

---@param commit string
local function check_head_hash(commit)
  if vim.fn.executable('git') ~= 1 then
    vim.health.warn('Cannot check for updates: git not found')
    return
  end
  local result = vim
    .system({ 'git', 'ls-remote', 'https://github.com/neovim/neovim', 'HEAD' }, { text = true })
    :wait()
  if result.code ~= 0 then
    return
  end
  local upstream = result.stdout:match('^(%x+)')
  if not upstream then
    return
  end
  if upstream:sub(1, #commit) ~= commit then
    vim.health.warn(
      ('Build is outdated. Local: %s, Latest: %s'):format(commit, upstream:sub(1, 12))
    )

Review comment (suggestion):
```suggestion
        string.format('Nvim %s is available (current: %s)', latest_version, current_version)
```

Code after:
  return 'unknown'
end

---@param nvim_version string
local function check_stable_version(nvim_version)
  local result = vim
    .system(
      { 'git', 'ls-remote', '--tags', 'https://github.com/neovim/neovim' },
      { text = true, timeout = 5000 }
    )
    :wait()
  if result.code ~= 0 or not result.stdout or result.stdout == '' then
    return
  end
  local stable_sha = result.stdout:match('(%x+)%s+refs/tags/stable%^{}')
    or result.stdout:match('(%x+)%s+refs/tags/stable\n')
  if not stable_sha then
    return
  end
  local latest_version = result.stdout:match(stable_sha .. '%s+refs/tags/v?(%d+%.%d+%.%d+)%^{}')
  if not latest_version then
    return
  end
  local current_version = nvim_version:match('v?(%d+%.%d+%.%d+)')
  if not current_version then
    return
  end
  local current = vim.version.parse(current_version)
  local latest = vim.version.parse(latest_version)
  if current and latest and vim.version.lt(current, latest) then
    vim.health.warn(('Nvim %s is available (current: %s)'):format(latest_version, current_version))
  else
    vim.health.ok(('Up to date (%s)'):format(current_version))
  end
end

---@param commit string
local function check_head_hash(commit)
  local result = vim
    .system(
      { 'git', 'ls-remote', 'https://github.com/neovim/neovim', 'HEAD' },
      { text = true, timeout = 5000 }
    )
    :wait()
  if result.code ~= 0 or not result.stdout or result.stdout == '' then
    return
  end
  local upstream = result.stdout:match('^(%x+)')
  if not upstream then
    return
  end