From 7d5caaccbbccf30785c37e92070162edfa468081 Mon Sep 17 00:00:00 2001 From: Shane da Silva Date: Tue, 10 Nov 2026 18:50:51 -0800 Subject: [PATCH 1/2] Bump version to 0.76.0 Missed in 4a73ef31. --- lib/overcommit/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/overcommit/version.rb b/lib/overcommit/version.rb index eba1d2c4..8c8deed6 100644 --- a/lib/overcommit/version.rb +++ b/lib/overcommit/version.rb @@ -2,5 +2,5 @@ # Defines the gem version. module Overcommit - VERSION = '0.75.0' + VERSION = '0.76.0' end From 53739b9e14a26dcaa02ebd94821e395c7852006b Mon Sep 17 00:00:00 2001 From: Shane da Silva Date: Tue, 10 Nov 2026 19:00:01 -0800 Subject: [PATCH 2/2] Keep spell-check message file alive during execution --- lib/overcommit/hook/commit_msg/spell_check.rb | 13 +++++------- spec/overcommit/hook/additional_hook_spec.rb | 20 ++++++++++++++++++- .../hook/commit_msg/spell_check_spec.rb | 3 +-- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lib/overcommit/hook/commit_msg/spell_check.rb b/lib/overcommit/hook/commit_msg/spell_check.rb index ec6c4d4a..b66e27a7 100644 --- a/lib/overcommit/hook/commit_msg/spell_check.rb +++ b/lib/overcommit/hook/commit_msg/spell_check.rb @@ -12,7 +12,11 @@ class SpellCheck < Base MISSPELLING_REGEX = /^[&#]\s(?\w+)(?:.+?:\s(?.*))?/.freeze def run - result = execute(command + [uncommented_commit_msg_file]) + result = ::Tempfile.create('commit-msg') do |file| + file.write(commit_message) + file.close + execute(command + [file.path]) + end return [:fail, "Error running spellcheck: #{result.stderr.chomp}"] unless result.success? misspellings = parse_misspellings(result.stdout) @@ -29,13 +33,6 @@ def run private - def uncommented_commit_msg_file - ::Tempfile.open('commit-msg') do |file| - file.write(commit_message) - file.path - end - end - def parse_misspellings(output) output.scan(MISSPELLING_REGEX).map do |word, suggestions| Misspelling.new(word, suggestions) diff --git a/spec/overcommit/hook/additional_hook_spec.rb b/spec/overcommit/hook/additional_hook_spec.rb index 2ac4ce26..64bf94d2 100644 --- a/spec/overcommit/hook/additional_hook_spec.rb +++ b/spec/overcommit/hook/additional_hook_spec.rb @@ -17,11 +17,29 @@ it 'passes uncommented commit messages to the spelling checker' do hook = Overcommit::Hook::CommitMsg::SpellCheck.new(config, double('context', commit_message: 'Subject')) + message_file = nil expect(hook).to receive(:execute) do |command| - expect(File).to exist(command.last) + message_file = command.last + GC.start + expect(File).to exist(message_file) + expect(File.read(message_file)).to eq('Subject') double('result', success?: true, stdout: '') end expect(hook.run).to eq(:pass) + expect(File).not_to exist(message_file) + end + + it 'removes the spelling checker message file when execution raises' do + hook = Overcommit::Hook::CommitMsg::SpellCheck.new(config, + double('context', commit_message: 'Subject')) + message_file = nil + expect(hook).to receive(:execute) do |command| + message_file = command.last + expect(File).to exist(message_file) + raise 'spell checker failed' + end + expect { hook.run }.to raise_error('spell checker failed') + expect(File).not_to exist(message_file) end it 'checks real submodule statuses with the configured recursive option' do diff --git a/spec/overcommit/hook/commit_msg/spell_check_spec.rb b/spec/overcommit/hook/commit_msg/spell_check_spec.rb index 6eae073f..a4a61cc3 100644 --- a/spec/overcommit/hook/commit_msg/spell_check_spec.rb +++ b/spec/overcommit/hook/commit_msg/spell_check_spec.rb @@ -4,11 +4,10 @@ describe Overcommit::Hook::CommitMsg::SpellCheck do let(:config) { Overcommit::ConfigurationLoader.default_configuration } - let(:context) { double('context') } + let(:context) { double('context', commit_message: 'Subject') } subject { described_class.new(config, context) } before do - subject.stub(:uncommented_commit_msg_file) subject.stub(:execute).and_return(result) end