Skip to content

Commit f9ecdcb

Browse files
authored
Partial log flushing to make long hooks intuitive (#777)
* Update specs to work when global config is using `main` for initial branch * Support flushing logs to allow long scripts to become obvious
1 parent 7362996 commit f9ecdcb

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

lib/overcommit/logger.rb

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ def newline
3131
log
3232
end
3333

34+
# Flushes the [IO] object for partial lines
35+
def flush
36+
@out.flush if @out.respond_to? :flush
37+
end
38+
3439
# Write a line of output.
3540
#
3641
# A newline character will always be appended.

lib/overcommit/printer.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,14 @@ def end_hook(hook, status, output)
4343
end
4444

4545
def interrupt_triggered
46-
log.newline
47-
log.error 'Interrupt signal received. Stopping hooks...'
46+
log.error "\nInterrupt signal received. Stopping hooks..."
4847
end
4948

5049
# Executed when a hook run was interrupted/cancelled by user.
5150
def run_interrupted
5251
log.newline
5352
log.warning '⚠ Hook run interrupted by user'
54-
log.warning '⚠ If files appear modified/missing, check your stash to recover them'
55-
log.newline
53+
log.warning "⚠ If files appear modified/missing, check your stash to recover them\n"
5654
end
5755

5856
# Executed when one or more hooks by the end of the run.
@@ -91,6 +89,7 @@ def print_header(hook)
9189
log.partial hook.description
9290
log.partial '.' * [70 - hook.description.length - hook_name.length, 0].max
9391
log.partial hook_name
92+
log.flush
9493
end
9594

9695
def print_result(hook, status, output) # rubocop:disable Metrics/CyclomaticComplexity

spec/spec_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require 'bundler'
34
require 'simplecov'
45
SimpleCov.start do
56
add_filter 'bin/'

spec/support/git_spec_helpers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module GitSpecHelpers
1313
# @return [String] path of the repository
1414
def repo(options = {})
1515
directory('some-repo') do
16-
create_cmd = %w[git init]
16+
create_cmd = %w[git init --initial-branch=master]
1717
create_cmd += ['--template', options[:template_dir]] if options[:template_dir]
1818
create_cmd += ['--separate-git-dir', options[:git_dir]] if options[:git_dir]
1919

0 commit comments

Comments
 (0)