Skip to content

Commit 1e8b3df

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

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lua/tinygit/commands/commit.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ 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" }):wait()
80+
if u.nonZeroExit(preCommitResult) then return end
81+
7882
require("tinygit.commands.commit.msg-input").new(inputMode, prompt, function(title, body)
7983
-- stage
8084
if doStageAllChanges then
@@ -83,7 +87,8 @@ function M.smartCommit(opts)
8387
end
8488

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

0 commit comments

Comments
 (0)