Skip to content

Commit 02ff063

Browse files
committed
chore: code cleanup
1 parent 413997e commit 02ff063

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lua/tinygit/commands/commit-and-amend.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ local function setupInputField(commitType)
232232
if commitType == "smartCommit" then
233233
vim.api.nvim_create_autocmd("WinClosed", {
234234
callback = function(ctx)
235-
local ft = vim.api.nvim_get_option_value("filetype", { buf = ctx.buf })
236-
if not (ft == "gitcommit" or ft == "DressingInput") then return end
235+
local ft = vim.bo[ctx.buf].filetype
236+
if ft ~= "gitcommit" and ft ~= "DressingInput" then return end
237237

238238
local cwd = vim.uv.cwd() or ""
239239
M.state.abortedCommitMsg[cwd] = vim.api.nvim_buf_get_lines(ctx.buf, 0, 1, false)[1]

lua/tinygit/commands/push-pull.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,27 @@ end
2424
local function pushCmd(opts)
2525
local config = require("tinygit.config").config.push
2626
local gitCommand = { "git", "push" }
27+
local title = opts.forceWithLease and "Force push" or "Push"
2728
if opts.forceWithLease then table.insert(gitCommand, "--force-with-lease") end
2829

2930
vim.system(
3031
gitCommand,
31-
{ detach = true, text = true },
32+
{ detach = true },
3233
vim.schedule_wrap(function(result)
33-
local out = vim.trim((result.stdout or "") .. (result.stderr or "")):gsub("\n%s+", "\n") -- fix leading spacing
34+
local out = vim.trim((result.stdout or "") .. (result.stderr or ""))
35+
out = out:gsub("\n%s+", "\n") -- remove padding
3436
local commitRange = out:match("%x+%.%.%x+")
3537

3638
-- notify
3739
if result.code == 0 then
3840
local numOfPushedCommits = u.syncShellCmd { "git", "rev-list", "--count", commitRange }
3941
if numOfPushedCommits ~= "" then
4042
local plural = numOfPushedCommits ~= "1" and "s" or ""
41-
-- `[]` together with `ft=markdown` -> simple highlighting for `snacks.nvim`
42-
out = out .. ("\n[%s commit%s]"):format(numOfPushedCommits, plural)
43+
-- `[]` -> simple highlighting for `snacks.nvim`
44+
out = out .. ("\n[%d commit%s]"):format(numOfPushedCommits, plural)
4345
end
4446
end
45-
u.notify(out, result.code == 0 and "info" or "error", { ft = ft, title = "Push" })
47+
u.notify(out, result.code == 0 and "info" or "error", { title = title })
4648

4749
-- sound
4850
if config.confirmationSound and jit.os == "OSX" then
@@ -67,6 +69,8 @@ end
6769
---@param calledByCommitFunc? boolean
6870
function M.push(opts, calledByCommitFunc)
6971
local config = require("tinygit.config").config.push
72+
if not opts then opts = {} end
73+
local title = opts.forceWithLease and "Force push" or "Push"
7074

7175
-- GUARD
7276
if u.notInGitRepo() then return end
@@ -75,12 +79,10 @@ function M.push(opts, calledByCommitFunc)
7579
u.syncShellCmd { "git", "log", "--oneline", "--grep=^fixup!", "--grep=^squash!" }
7680
if fixupOrSquashCommits ~= "" then
7781
local msg = "Aborting: There are fixup or squash commits.\n\n" .. fixupOrSquashCommits
78-
u.notify(msg, "warn", { title = "Push" })
82+
u.notify(msg, "warn", { title = title })
7983
return
8084
end
8185
end
82-
if not opts then opts = {} end
83-
local title = opts.forceWithLease and "Force push" or "Push"
8486

8587
-- extra notification when called by user
8688
if not calledByCommitFunc then
@@ -115,7 +117,7 @@ function M.push(opts, calledByCommitFunc)
115117
-- Pull & Push
116118
vim.system(
117119
{ "git", "pull" },
118-
{ detach = true, text = true },
120+
{ detach = true },
119121
vim.schedule_wrap(function(result)
120122
-- Git messaging is weird and sometimes puts normal messages into
121123
-- stderr, thus we need to merge stdout and stderr.

0 commit comments

Comments
 (0)