Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/overcommit/hook/pre_push/protected_branches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Overcommit::Hook::PrePush
# Prevents destructive updates to specified branches.
class ProtectedBranches < Base
def run
log_pushed_refs
return :pass unless illegal_pushes.any?

messages = illegal_pushes.map do |pushed_ref|
Expand All @@ -13,6 +14,15 @@ def run

private

def log_pushed_refs
log_msg = "\nPushed refs:\n\t#{pushed_refs_str}"
Overcommit::Utils.log.debug(log_msg)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printing debug messages breaks the output of the hook with the way we currently output OK/FAIL at the end of the hook's run, so I'd be hesitant to commit this in even if it only appeared with OVERCOMMIT_DEBUG=1.

This has come up a few times, so it seems like we need to expose a call that allows a hook to aggregate log messages which are printed in addition to its regular output when debugging is enabled (but printed at the end of the hook run).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. We'd need to gate the run in a begin...ensure block so that log messages are printed even if the hook run throws an exception.

end

def pushed_refs_str
pushed_refs.map(&:to_s).join("\t\n")
end

def branches
@branches ||= config['branches']
end
Expand Down