Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nvim): fzf git log on fugitive special commit #652

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions nvim/config--nvim--init.vim.symlink
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ function commit_and_path()
if parsed[2] ~= '' then -- we parsed a fugitive:// url
local commit, path = unpack(vim.fn.split(parsed[1], ':'))

if string.match(commit, "^[0-3]$") then -- special fugitive commit
-- Reset to HEAD to match fugitive's gclog function's behavior.
-- There is no obvious, public function to restore the actual commit hash from.
-- For "0", there would not be a matching commit hash (other than HEAD anyhow).
commit = "HEAD"
end

local worktree = vim.fn.FugitiveWorkTree()
local abs_path = path and worktree .. '/' .. path or worktree
return {commit or "HEAD", abs_path}
Expand Down
35 changes: 32 additions & 3 deletions nvim/tests/fzf-git.test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ function Test_CopiedFileFollow()
call assert_match('firstfile$', bufname(), 'Wrong file name (copied-from)')
endfunction

function Check_DifferentPwd(id)
function Check_Preview(id)
call WaitForFzfResults(1)

call WaitForScreenContent('Author:\|fatal:')
Expand Down Expand Up @@ -486,15 +486,44 @@ function Test_DifferentPwd()
" English language necessary to check for "fatal:" and "Author:" strings
call setenv('LC_ALL', 'en_US.UTF8')

call timer_start(50, funcref('Check_DifferentPwd'))
call timer_start(50, funcref('Check_Preview'))
call feedkeys(',gl', 'tx!')

" Explicitly use the HEAD version of the 'firstfile'
Gedit HEAD:%

call timer_start(50, funcref('Check_DifferentPwd'))
call timer_start(50, funcref('Check_Preview'))
call feedkeys(',gl', 'tx!')

" Explicitly use the staging version of the 'firstfile'
Gedit :0:%

call timer_start(50, funcref('Check_Preview'))
call feedkeys(',gl', 'tx!')
endfunction

" showing commit history of a buffer should still working on the staging
" / etc. buffers that are extensions in fugitive with ":0", ":1", ":2", ":3"
" Since those are not properly integrated in fugitive as well (e.g., copying
" the commit hash with "y ctrl-g" leaves the special hashes unresolved.
" Moreover, "0" references the staging area, which by design has no hash
" associated.
function Test_SpecialCommit()
call CdTestDir()

call RunSystemCommand(['git', 'init'])
call assert_equal(0, writefile(['something', 'something2', 'something3'], 'firstfile'))
call RunSystemCommand(['git', 'add', 'firstfile'])
call RunSystemCommand(['git', 'commit', '-m', 'first commit', '--no-verify', '--no-gpg-sign'])

edit firstfile
Gedit :0:%

" English language necessary to check for "fatal:" and "Author:" strings
call setenv('LC_ALL', 'en_US.UTF8')

call timer_start(50, funcref('Check_Preview'))
call feedkeys(',gl', 'tx!')
endfunction

function Test()
Expand Down