mirror of
https://github.com/neovim/neovim.git
synced 2025-12-14 02:22:49 +00:00
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).
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 ─────────────────────────────────────────────────────────────────────────} |',
|
||||
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user