Skip to content

Commit

Permalink
fix: get the repo version of the username
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Jul 3, 2024
1 parent d44a794 commit 2e5719c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
6 changes: 5 additions & 1 deletion lua/gitsigns/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ M.Obj = Obj
--- @field abbrev_head string

--- @class Gitsigns.Repo : Gitsigns.RepoInfo
---
--- Username configured for the repo.
--- Needed for to determine "You" in current line blame.
--- @field username string
local Repo = {}
M.Repo = Repo
Expand Down Expand Up @@ -328,7 +331,6 @@ end
function Repo.new(dir, gitdir, toplevel)
local self = setmetatable({}, { __index = Repo })

self.username = git_command({ 'config', 'user.name' }, { ignore_error = true })[1]
local info = M.get_repo_info(dir, nil, gitdir, toplevel)
for k, v in
pairs(info --[[@as table<string,any>]])
Expand All @@ -337,6 +339,8 @@ function Repo.new(dir, gitdir, toplevel)
self[k] = v
end

self.username = self:command({ 'config', 'user.name' }, { ignore_error = true })[1]

return self
end

Expand Down
2 changes: 1 addition & 1 deletion test/gitdir_watcher_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ describe('gitdir_watcher', function()

match_debug_messages({
'attach(1): Attaching (trigger=BufReadPost)',
np('run_job: git .* config user.name'),
np(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* config user.name'),
np('run_job: git .* ls%-files .* ' .. vim.pesc(test_file)),
n('watch_gitdir(1): Watching git dir'),
np('run_job: git .* show .*'),
Expand Down
21 changes: 8 additions & 13 deletions test/gitsigns_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ describe('gitsigns (with screen)', function()

match_debug_messages({
'attach(1): Attaching (trigger=BufReadPost)',
np('run_job: git .* config user.name'),
np(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* config user.name'),
n('new: Not in git repo'),
n('attach(1): Empty git obj'),
})
Expand All @@ -139,10 +139,10 @@ describe('gitsigns (with screen)', function()

match_debug_messages({
n('attach(1): Attaching (trigger=BufWritePost)'),
np('run_job: git .* config user.name'),
np(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* config user.name'),
n('new: Not in git repo'),
n('attach(1): Empty git obj'),
})
Expand Down Expand Up @@ -192,10 +192,10 @@ describe('gitsigns (with screen)', function()

match_debug_messages({
'attach(1): Attaching (trigger=BufReadPost)',
np('run_job: git .* config user.name'),
np(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* config user.name'),
np('run_job: git .* ls%-files .*/dummy_ignored.txt'),
n('attach(1): Cannot resolve file in repo'),
})
Expand All @@ -208,10 +208,10 @@ describe('gitsigns (with screen)', function()

match_debug_messages({
'attach(1): Attaching (trigger=BufNewFile)',
np('run_job: git .* config user.name'),
np(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* config user.name'),
np(
'run_job: git .* ls%-files %-%-stage %-%-others %-%-exclude%-standard %-%-eol '
.. vim.pesc(newfile)
Expand Down Expand Up @@ -288,14 +288,9 @@ describe('gitsigns (with screen)', function()
feed('gg')
check({ signs = {} })

-- Wait until the virtual blame line appears
-- screen:sleep(500)
-- print(vim.inspect(exec_lua[[return require'gitsigns.cache'.cache[vim.api.nvim_get_current_buf()].compare_text]]))
-- print(vim.inspect(exec_lua[[return require'gitsigns.util'.buf_lines(vim.api.nvim_get_current_buf())]]))

screen:expect({
grid = [[
^{MATCH:This {6: tester, %d seco}}|
^{MATCH:This {6: You, %d second.}}|
is |
a |
windows |
Expand Down Expand Up @@ -349,11 +344,11 @@ describe('gitsigns (with screen)', function()
edit(test_file)
match_debug_messages({
'attach(1): Attaching (trigger=BufReadPost)',
np('run_job: git .* config user.name'),
np(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* rev%-parse %-%-short HEAD'),
np('run_job: git .* config user.name'),
np('run_job: git .* %-%-git%-dir .* %-%-stage %-%-others %-%-exclude%-standard %-%-eol.*'),
n('attach(1): User on_attach() returned false'),
})
Expand Down Expand Up @@ -466,21 +461,21 @@ describe('gitsigns (with screen)', function()
edit(newfile)
match_debug_messages({
'attach(1): Attaching (trigger=BufNewFile)',
np('run_job: git .* config user.name'),
np(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* config user.name'),
np('run_job: git .* ls%-files .*'),
n('attach(1): Not a file'),
})
command('write')

local messages = {
'attach(1): Attaching (trigger=BufWritePost)',
np('run_job: git .* config user.name'),
np(
'run_job: git .* rev%-parse %-%-show%-toplevel %-%-absolute%-git%-dir %-%-abbrev%-ref HEAD'
),
np('run_job: git .* config user.name'),
np('run_job: git .* ls%-files .*'),
n('watch_gitdir(1): Watching git dir'),
}
Expand Down

0 comments on commit 2e5719c

Please sign in to comment.