Skip to content

Commit 18a98bf

Browse files
committed
fix(keymaps): improve git fetch keymap to use fidget and show errors
Refactored the <leader>gpf keymap to use utils.lazy_cmd_with_fidget for better feedback and error reporting. Updated group label for clarity. Also enhanced utils to notify on stderr output.
1 parent b0d52e8 commit 18a98bf

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

lua/dcai/keymaps/git.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ local git_keymap = {
105105
},
106106
{
107107
'<leader>gp',
108-
group = 'pull and push',
108+
group = 'pull/fetch and push',
109109
},
110110
{
111111
'<leader>gpr',
@@ -126,7 +126,10 @@ local git_keymap = {
126126
},
127127
{
128128
'<leader>gpf',
129-
lazy_git_cmd({ args = { 'fetch', '--tags', '--all', '--verbose' } }),
129+
utils.lazy_cmd_with_fidget(
130+
'git',
131+
{ 'fetch', '--tags', '--all', '--verbose' }
132+
),
130133
desc = 'git fetch',
131134
},
132135
}

lua/dcai/keymaps/utils.lua

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,25 @@ M.lazy_cmd = function(command, args, opts)
1919
args = args or {}
2020
local cwd = opts.cwd or vim.fn.getcwd()
2121

22-
Job
23-
:new({
24-
command = command,
25-
args = args,
26-
cwd = cwd,
27-
on_exit = vim.schedule_wrap(function(job, ret)
28-
local stderr = table.concat(job:stderr_result(), vim.g.nl)
29-
local stdout = table.concat(job:result(), vim.g.nl)
22+
Job:new({
23+
command = command,
24+
args = args,
25+
cwd = cwd,
26+
on_exit = vim.schedule_wrap(function(job, ret)
27+
local stderr = table.concat(job:stderr_result(), vim.g.nl)
28+
local stdout = table.concat(job:result(), vim.g.nl)
3029

31-
if ret == 0 then
32-
if opts.on_success then
33-
opts.on_success(stdout, stderr)
34-
end
35-
else
36-
if opts.on_error then
37-
opts.on_error(stdout, stderr, ret)
38-
end
30+
if ret == 0 then
31+
if opts.on_success then
32+
opts.on_success(stdout, stderr)
3933
end
40-
end),
41-
})
42-
:start()
34+
else
35+
if opts.on_error then
36+
opts.on_error(stdout, stderr, ret)
37+
end
38+
end
39+
end),
40+
}):start()
4341
end
4442
end
4543

@@ -73,11 +71,7 @@ local function lazy_cmd_with_window(command, opts, desc)
7371
popupwin.append(stderr)
7472
else
7573
vim.notify(
76-
command
77-
.. ''
78-
.. table.concat(args, ',')
79-
.. ' failed: '
80-
.. stderr
74+
command .. '' .. table.concat(args, ',') .. ' failed: ' .. stderr
8175
)
8276
end
8377
end,
@@ -89,7 +83,8 @@ M.lazy_cmd_with_window = lazy_cmd_with_window
8983
M.lazy_cmd_with_fidget = function(command, args, opts)
9084
return function()
9185
opts = opts or {}
92-
local command_full = string.format('%s %s', command, table.concat(args, ' '))
86+
local command_full =
87+
string.format('%s %s', command, table.concat(args, ' '))
9388

9489
-- Create fidget progress handle
9590
local fidget_progress = require('fidget.progress')
@@ -106,6 +101,9 @@ M.lazy_cmd_with_fidget = function(command, args, opts)
106101
if stdout ~= '' then
107102
vim.notify(stdout, vim.log.levels.INFO)
108103
end
104+
if stderr ~= '' then
105+
vim.notify(stderr, vim.log.levels.ERROR)
106+
end
109107
handle:finish()
110108
end,
111109
on_error = function(stdout, stderr, ret)

0 commit comments

Comments
 (0)