feat(pack): update get() to take rev from actual repo if info=true

Problem: `vim.pack.get()` always uses lockfile as the source for the
  `rev` field. This is fast, but may be misleading in case of
  a corrupted lockfile.

Solution: Compute revision from Git repo on disk if `info=true`
  (default), use lockfile otherwise. This does increase execution time
  (as a result of one extra `git ...` call for every plugin), but
  `info=true` is already designed to be informative and not necessarily
  fast.
This commit is contained in:
Evgeni Chasnovski
2026-05-17 10:49:48 +03:00
parent 7d99104058
commit 8d100483e0
3 changed files with 25 additions and 10 deletions

View File

@@ -1434,7 +1434,7 @@ end
--- @field active boolean Whether plugin was added via |vim.pack.add()| to current session.
--- @field branches? string[] Available Git branches (first is default). Missing if `info=false`.
--- @field path string Plugin's path on disk.
--- @field rev string Current Git revision.
--- @field rev string Current Git revision. Taken from |vim.pack-lockfile| if `info=false`.
--- @field spec vim.pack.SpecResolved A |vim.pack.Spec| with resolved `name`.
--- @field tags? string[] Available Git tags. Missing if `info=false`.
@@ -1450,6 +1450,7 @@ local function add_p_data_info(p_data_list)
--- @async
funs[i] = function()
p_data.branches = git_get_branches(path)
p_data.rev = git_get_hash('HEAD', path)
p_data.tags = git_get_tags(path)
end
end