[git] Fix prepare-commit-message hook to not mess with rebases

This commit is contained in:
Sebastian Schulze 2020-02-26 11:09:37 +01:00
parent 0fb9ddb7d5
commit 8f6f8a265c
Signed by: bascht
GPG Key ID: 5BCB1D3B4D38A35A
1 changed files with 11 additions and 3 deletions

14
dot_config/git/hooks/executable_prepare-commit-msg Executable file → Normal file
View File

@ -3,14 +3,22 @@
abort "No tempfile given" if ARGV.empty? abort "No tempfile given" if ARGV.empty?
commit_file = ARGV[0] commit_file = ARGV[0]
commit_msg = File.read(commit_file) 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 (?<ticket>[A-Z]{1,10}-\d+)}) branch_match = commit_msg.match(%r{# On branch (?<ticket>[A-Z]{1,10}-\d+)})
if branch_match.nil? or branch_match["ticket"].nil? 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 exit
end end