commit f3f509563084104963824772b4694859e4f665bc
parent f2bfde9140ca646db3e2b67b97b1e54b70408703
Author: Evgeni Chasnovski <evgeni.chasnovski@gmail.com>
Date: Thu, 6 Nov 2025 18:42:36 +0200
fix(pack): use full hashes in lockfile and revision description
Problem: Using abbreviated version of commit hashes might be unreliable
in the long term (although highly unlikely).
Solution: Use full hashes in lockfile and revision description (in
confirmation buffer and log). Keep abbreviated hashes when displaying
update changes (for brevity).
Diffstat:
2 files changed, 24 insertions(+), 20 deletions(-)
diff --git a/runtime/lua/vim/pack.lua b/runtime/lua/vim/pack.lua
@@ -193,7 +193,7 @@ end
local function git_get_hash(ref, cwd)
-- Using `rev-list -1` shows a commit of reference, while `rev-parse` shows
-- hash of reference. Those are different for annotated tags.
- return git_cmd({ 'rev-list', '-1', '--abbrev-commit', ref }, cwd)
+ return git_cmd({ 'rev-list', '-1', ref }, cwd)
end
--- @async
diff --git a/test/functional/plugin/pack_spec.lua b/test/functional/plugin/pack_spec.lua
@@ -103,6 +103,10 @@ local function git_add_commit(msg, repo_name)
end
local function git_get_hash(rev, repo_name)
+ return git_cmd({ 'rev-list', '-1', rev }, repo_name)
+end
+
+local function git_get_short_hash(rev, repo_name)
return git_cmd({ 'rev-list', '-1', '--abbrev-commit', rev }, repo_name)
end
@@ -906,8 +910,9 @@ describe('vim.pack', function()
describe('update()', function()
-- Lua source code for the tested plugin named "fetch"
local fetch_lua_file = vim.fs.joinpath(pack_get_plug_path('fetch'), 'lua', 'fetch.lua')
- -- Table with hashes used to test confirmation buffer and log content
+ -- Tables with hashes used to test confirmation buffer and log content
local hashes --- @type table<string,string>
+ local short_hashes --- @type table<string,string>
before_each(function()
-- Create a dedicated clean repo for which "push changes" will be mocked
@@ -920,6 +925,7 @@ describe('vim.pack', function()
git_add_commit('Commit from `main` to be removed', 'fetch')
hashes = { fetch_head = git_get_hash('HEAD', 'fetch') }
+ short_hashes = { fetch_head = git_get_short_hash('HEAD', 'fetch') }
-- Install initial versions of tested plugins
exec_lua(function()
@@ -1027,7 +1033,8 @@ describe('vim.pack', function()
screen = Screen.new(85, 35)
hashes.fetch_new = git_get_hash('main', 'fetch')
- hashes.fetch_new_prev = git_get_hash('main~', 'fetch')
+ short_hashes.fetch_new = git_get_short_hash('main', 'fetch')
+ short_hashes.fetch_new_prev = git_get_short_hash('main~', 'fetch')
hashes.semver_head = git_get_hash('v0.3.0', 'semver')
local tab_name = 'n' .. (t.is_os('win') and ':' or '') .. '//2/confirm-update'
@@ -1050,22 +1057,18 @@ describe('vim.pack', function()
'{101:## fetch} |',
'Path: {103:FETCH_PATH} |',
'Source: {103:FETCH_SRC} |',
- ('State before: {103:%s} |'):format(
- hashes.fetch_head
- ),
- ('State after: {103:%s} {102:(main)} |'):format(
- hashes.fetch_new
- ),
+ ('State before: {103:%s} |'):format(hashes.fetch_head),
+ ('State after: {103:%s} {102:(main)} |'):format(hashes.fetch_new),
' |',
'Pending updates: |',
('{19:< %s │ Commit from `main` to be removed} |'):format(
- hashes.fetch_head
+ short_hashes.fetch_head
),
('{104:> %s │ Commit to be added 2} |'):format(
- hashes.fetch_new
+ short_hashes.fetch_new
),
('{104:> %s │ Commit to be added 1 (tag: dev-tag)} |'):format(
- hashes.fetch_new_prev
+ short_hashes.fetch_new_prev
),
' |',
'{102:# Same ─────────────────────────────────────────────────────────────────────────} |',
@@ -1073,7 +1076,7 @@ describe('vim.pack', function()
'{102:## semver} |',
'Path: {103:SEMVER_PATH} |',
'Source: {103:SEMVER_SRC} |',
- ('State: {103:%s} {102:(v0.3.0)} |'):format(
+ ('State: {103:%s} {102:(v0.3.0)} |'):format(
hashes.semver_head
),
' |',
@@ -1129,9 +1132,9 @@ describe('vim.pack', function()
fetch_src,
hashes.fetch_head,
hashes.fetch_new,
- hashes.fetch_head,
- hashes.fetch_new,
- hashes.fetch_new_prev
+ short_hashes.fetch_head,
+ short_hashes.fetch_new,
+ short_hashes.fetch_new_prev
)
eq(vim.text.indent(0, ref_log_lines), vim.trim(log_rest))
end)
@@ -1456,7 +1459,8 @@ describe('vim.pack', function()
-- Write to log file
hashes.fetch_new = git_get_hash('main', 'fetch')
- hashes.fetch_new_prev = git_get_hash('main~', 'fetch')
+ short_hashes.fetch_new = git_get_short_hash('main', 'fetch')
+ short_hashes.fetch_new_prev = git_get_short_hash('main~', 'fetch')
local log_path = vim.fs.joinpath(fn.stdpath('log'), 'nvim-pack.log')
local log_text = fn.readblob(log_path)
@@ -1479,9 +1483,9 @@ describe('vim.pack', function()
fetch_src,
hashes.fetch_head,
hashes.fetch_new,
- hashes.fetch_head,
- hashes.fetch_new,
- hashes.fetch_new_prev
+ short_hashes.fetch_head,
+ short_hashes.fetch_new,
+ short_hashes.fetch_new_prev
)
eq(vim.text.indent(0, ref_log_lines), vim.trim(log_rest))