Skip to content

Commit e439531

Browse files
committed
feat(smartCommit): check that pre-commit passes before opening msg input
1 parent c717753 commit e439531

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lua/tinygit/commands/commit.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ function M.smartCommit(opts)
7575

7676
local inputMode = doStageAllChanges and "stage-all-and-commit" or "commit"
7777

78+
-- check if pre-commit would pass before opening message input
79+
local preCommitResult = vim.system({ "git", "hook", "run", "--ignore-missing", "pre-commit" })
80+
:wait()
81+
if u.nonZeroExit(preCommitResult) then return end
82+
7883
require("tinygit.commands.commit.msg-input").new(inputMode, prompt, function(title, body)
7984
-- stage
8085
if doStageAllChanges then
@@ -83,7 +88,8 @@ function M.smartCommit(opts)
8388
end
8489

8590
-- commit
86-
local commitArgs = { "git", "commit", "--message=" .. title }
91+
-- (using `--no-verify`, since we checked the pre-commit earlier already)
92+
local commitArgs = { "git", "commit", "--no-verify", "--message=" .. title }
8793
if body then table.insert(commitArgs, "--message=" .. body) end
8894
local result = vim.system(commitArgs):wait()
8995
if u.nonZeroExit(result) then return end

0 commit comments

Comments
 (0)