Files
textmate/bin/update_changes
Allan Odgaard d5d017ea88 Use git’s ‘--reverse’ option instead of ‘tail -r’
This avoids an extra process but also removes a dependency on BSD’s tail command, as support for ‘-r’ is not a POSIX requirement.
2019-09-15 16:20:40 +02:00

39 lines
1.3 KiB
Ruby
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby -w
require 'optparse'
PROGRAM_NAME = File.basename(__FILE__)
new_tag = nil
OptionParser.new do |opts|
opts.banner = "Usage: #{PROGRAM_NAME} [options]"
opts.on('-t', '--tag=name', 'Tag to use for next release.') { |value| new_tag = value }
opts.on_tail('-h', '--help', 'Show this message.') { puts opts; exit }
end.parse!
abort "#{PROGRAM_NAME}: No release tag specified, use -t/--tag." if new_tag.nil?
did_output = false
ARGF.each do |line|
if !did_output && line =~ %r{^#.*\b(v\d+(?:\.\d+)*(-\w+(?:\.\w+)*)?)}
old_tag = $1
abort "#{PROGRAM_NAME}: Changes already added for release tag #{old_tag}." if new_tag == old_tag
changes = %x{git log --pretty=tformat:'* %s *[%an]*' --date=short --reverse #{old_tag}..}
abort "#{PROGRAM_NAME}: Error calling git log: #{changes}" unless $? == 0
changes.gsub!(/\.?( \*\[(?:Allan Odgaard|(.+?))\]\*)$/) do
$2.nil? ? "." : ".#$1"
end
puts "## #{Time.now.strftime('%Y-%m-%d')} (#{new_tag})"
puts ""
puts changes
puts "* See [all changes since #{old_tag}](https://github.com/textmate/textmate/compare/#{old_tag}...#{new_tag})"
puts ""
did_output = true
end
puts line
end