Skip to content

Instantly share code, notes, and snippets.

@avsej
Last active December 10, 2015 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avsej/4510417 to your computer and use it in GitHub Desktop.
Save avsej/4510417 to your computer and use it in GitHub Desktop.
# encoding: utf-8
require 'fileutils'
require 'date'
files = `git ls-files`.split("\n")
files.each do |f|
next unless f =~ /\.(c|h|cc|ac|am|in)$/
contents = File.read(f)
if contents =~ /Copyright[-,\s\d]+Couchbase/
log = `git log --follow #{f}`.split("\n")
dates = log.map{|l| l[/Date:\s+(.*)/, 1]}.compact.map{|d| DateTime.parse(d).year}.uniq
if dates.size > 1
years = [dates[-1], dates[0]].join("-")
else
years = dates[0]
end
contents = contents.sub(/Copyright[-,\s\d]+Couchbase/, "Copyright #{years} Couchbase")
File.open(f, "w+"){|io| io.write(contents)}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment