diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index f984be6552..bdcb470308 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -191,6 +191,7 @@ LUA but returns `nil` on error. • |vim.pos| can now convert between positions and buffer offsets. • |vim.log| for easily creating loggers. +• |vim.pack.get()| output includes revision of a pending update. OPTIONS diff --git a/runtime/doc/pack.txt b/runtime/doc/pack.txt index 2a495ae3df..b17f9c1d79 100644 --- a/runtime/doc/pack.txt +++ b/runtime/doc/pack.txt @@ -498,6 +498,9 @@ get({names}, {opts}) *vim.pack.get()* • {path} (`string`) Plugin's path on disk. • {rev} (`string`) Current Git revision. Taken from |vim.pack-lockfile| if `info=false`. + • {rev_to}? (`string`) Git revision of a pending update. The same as + used during |vim.pack.update()| and which points to a resolved + `spec.version`. Missing if `info=false`. • {spec} (`vim.pack.SpecResolved`) A |vim.pack.Spec| with resolved `name`. • {tags}? (`string[]`) Available Git tags. Missing if `info=false`. diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua index 655d6f14d6..7eddacc3e2 100644 --- a/runtime/lua/vim/pack.lua +++ b/runtime/lua/vim/pack.lua @@ -1435,6 +1435,9 @@ end --- @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. Taken from |vim.pack-lockfile| if `info=false`. +--- Git revision of a pending update. The same as used during |vim.pack.update()| and which +--- points to a resolved `spec.version`. Missing if `info=false`. +--- @field rev_to? string --- @field spec vim.pack.SpecResolved A |vim.pack.Spec| with resolved `name`. --- @field tags? string[] Available Git tags. Missing if `info=false`. @@ -1445,13 +1448,18 @@ end --- @param p_data_list vim.pack.PlugData[] local function add_p_data_info(p_data_list) local funs = {} --- @type (async fun())[] + local plug_dir = get_plug_dir() for i, p_data in ipairs(p_data_list) do + local plug = new_plug(p_data.spec, plug_dir) local path = p_data.path --- @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) + + infer_revisions(plug) + p_data.rev = plug.info.sha_head + p_data.rev_to = plug.info.sha_target end end async_join_run_wait(funs) diff --git a/test/functional/plugin/pack_spec.lua b/test/functional/plugin/pack_spec.lua index f692e54e15..3963234642 100644 --- a/test/functional/plugin/pack_spec.lua +++ b/test/functional/plugin/pack_spec.lua @@ -2077,6 +2077,7 @@ describe('vim.pack', function() if info then res.branches = { 'main', 'feat-branch' } res.rev = git_get_hash('feat-branch', 'basic') + res.rev_to = res.rev res.tags = { 'some-tag' } else res.rev = get_lock_tbl().plugins.basic.rev @@ -2091,6 +2092,7 @@ describe('vim.pack', function() if info then res.branches = { 'dev', 'main' } res.rev = git_get_hash('dev', 'defbranch') + res.rev_to = res.rev res.tags = {} else res.rev = get_lock_tbl().plugins.defbranch.rev @@ -2106,6 +2108,7 @@ describe('vim.pack', function() if info then res.branches = { 'main' } res.rev = git_get_hash('v0.0.1', 'plugindirs') + res.rev_to = res.rev res.tags = { 'v0.0.1' } else res.rev = get_lock_tbl().plugins.plugindirs.rev @@ -2168,6 +2171,28 @@ describe('vim.pack', function() eq({ defbranch_data }, exec_lua('return vim.pack.get({ "defbranch" }, { info = false })')) end) + it('reports potential revision after update', function() + -- Install and set up different version without running `vim.pack.update()` + vim_pack_add({ repos_src.defbranch, { src = repos_src.basic, version = 'feat-branch' } }) + pack_assert_content('defbranch', 'return "defbranch dev"') + pack_assert_content('basic', 'return "basic feat-branch"') + + n.clear() + vim_pack_add({ { src = repos_src.defbranch, version = 'main' }, repos_src.basic }) + n.clear() + + -- Should report correct `rev_to` with active and not active plugins + vim_pack_add({ { src = repos_src.defbranch, version = 'main' } }) + local defbranch_data = make_defbranch_data(true, true) + defbranch_data.spec.version = 'main' + defbranch_data.rev_to = git_get_hash('main', 'defbranch') + local basic_data = make_basic_data(false, true) + basic_data.spec.version = nil + basic_data.rev_to = git_get_hash('main', 'basic') + + eq({ defbranch_data, basic_data }, exec_lua('return vim.pack.get()')) + end) + it('respects `data` field', function() vim_pack_add({ { src = repos_src.basic, version = 'feat-branch', data = { test = 'value' } },