From 8f6f8a265cf496f932ce75d335cc22d83cac12ce Mon Sep 17 00:00:00 2001 From: Sebastian Schulze Date: Wed, 26 Feb 2020 11:09:37 +0100 Subject: [PATCH] [git] Fix prepare-commit-message hook to not mess with rebases --- dot_config/git/hooks/executable_prepare-commit-msg | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) mode change 100755 => 100644 dot_config/git/hooks/executable_prepare-commit-msg diff --git a/dot_config/git/hooks/executable_prepare-commit-msg b/dot_config/git/hooks/executable_prepare-commit-msg old mode 100755 new mode 100644 index 7896b21..6bb1b99 --- a/dot_config/git/hooks/executable_prepare-commit-msg +++ b/dot_config/git/hooks/executable_prepare-commit-msg @@ -3,14 +3,22 @@ abort "No tempfile given" if ARGV.empty? commit_file = ARGV[0] - commit_msg = File.read(commit_file) -abort "No commit given" if commit_msg.nil? + +if commit_msg.nil? + $stderr.puts "Nothing given, aborting" + exit 0 +end + +unless commit_msg.lines.first.strip.empty? + $stderr.puts "Commit message not empty, aborting" + exit 0 +end branch_match = commit_msg.match(%r{# On branch (?[A-Z]{1,10}-\d+)}) if branch_match.nil? or branch_match["ticket"].nil? - puts "Could not extract a ticket from the commit message" + $stderr.puts "Could not extract a ticket from the commit message" exit end