Skip to content

Commit fcb1cd6

Browse files
committed
fix(ai_commit_msg): improve push command handling with terminal feedback
- update push mechanics to open a terminal buffer for feedback - display success or failure notifications based on exit status - retain functionality for pull-before-push configuration
1 parent 76bb498 commit fcb1cd6

1 file changed

Lines changed: 36 additions & 37 deletions

File tree

lua/ai_commit_msg/autocmds.lua

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,50 +46,49 @@ function M.setup(config)
4646
local prompt_message = string.format("Push commit to '%s'? (y/N): ", branch_name)
4747
vim.ui.input({ prompt = prompt_message }, function(input)
4848
if input and input:lower() == "y" then
49-
-- Pull-before-push configuration (table only)
5049
local pull_cfg = type(config.pull_before_push) == "table" and config.pull_before_push
5150
or { enabled = true, args = { "--rebase", "--autostash" } }
5251
local pull_enabled = (pull_cfg.enabled ~= false)
5352
local pull_args = type(pull_cfg.args) == "table" and pull_cfg.args or { "--rebase", "--autostash" }
5453

55-
if vim.fn.exists(":Git") > 0 then
56-
if pull_enabled then
57-
local args_str = table.concat(pull_args, " ")
58-
pcall(vim.cmd, "silent! Git pull " .. args_str)
59-
end
60-
vim.cmd("Git push")
61-
else
62-
vim.notify("Pushing commit...", vim.log.levels.INFO)
63-
local function do_push()
64-
vim.system({ "git", "push" }, {}, function(obj)
65-
vim.schedule(function()
66-
local output = obj.stdout or obj.stderr or ""
67-
if output ~= "" then
68-
vim.notify(vim.fn.trim(output), vim.log.levels.INFO)
69-
end
70-
end)
71-
end)
72-
end
54+
local function do_push()
55+
vim.cmd.tabnew()
56+
local term_buf = vim.api.nvim_get_current_buf()
57+
vim.fn.termopen("git push", {
58+
on_exit = function(_, exit_code, _)
59+
if exit_code == 0 then
60+
vim.schedule(function()
61+
vim.api.nvim_buf_delete(term_buf, { force = true })
62+
vim.notify("Push successful", vim.log.levels.INFO)
63+
end)
64+
else
65+
vim.schedule(function()
66+
vim.notify("Push failed - check terminal for details", vim.log.levels.ERROR)
67+
end)
68+
end
69+
end,
70+
})
71+
vim.cmd.startinsert()
72+
end
7373

74-
if pull_enabled then
75-
vim.notify("Pulling latest changes before push...", vim.log.levels.INFO)
76-
local cmd = { "git", "pull" }
77-
for _, a in ipairs(pull_args) do
78-
table.insert(cmd, a)
79-
end
80-
vim.system(cmd, {}, function(pull_obj)
81-
vim.schedule(function()
82-
if pull_obj.code == 0 then
83-
do_push()
84-
else
85-
local err = pull_obj.stderr or pull_obj.stdout or "git pull failed"
86-
vim.notify("git pull failed; aborting push: " .. vim.fn.trim(err), vim.log.levels.ERROR)
87-
end
88-
end)
89-
end)
90-
else
91-
do_push()
74+
if pull_enabled then
75+
vim.notify("Pulling latest changes before push...", vim.log.levels.INFO)
76+
local cmd = { "git", "pull" }
77+
for _, a in ipairs(pull_args) do
78+
table.insert(cmd, a)
9279
end
80+
vim.system(cmd, {}, function(pull_obj)
81+
vim.schedule(function()
82+
if pull_obj.code == 0 then
83+
do_push()
84+
else
85+
local err = pull_obj.stderr or pull_obj.stdout or "git pull failed"
86+
vim.notify("git pull failed; aborting push: " .. vim.fn.trim(err), vim.log.levels.ERROR)
87+
end
88+
end)
89+
end)
90+
else
91+
do_push()
9392
end
9493
end
9594
end)

0 commit comments

Comments
 (0)