Skip to content

Instantly share code, notes, and snippets.

@masiuchi
Last active June 18, 2017 09:30
Show Gist options
  • Save masiuchi/dfd1cb9342412df3d1ee9c108bb7b887 to your computer and use it in GitHub Desktop.
Save masiuchi/dfd1cb9342412df3d1ee9c108bb7b887 to your computer and use it in GitHub Desktop.
Forbit pushing in off time.
#!/usr/bin/env ruby
# -*- mode:ruby; coding:utf-8 -*-
require 'date'
require 'off_time_jp' # https://github.com/masiuchi/off_time_jp
if OffTimeJp.off_time?
puts 'Forbid pushing in off time'
exit false
end
branch = `git symbolic-ref --short HEAD`.chomp
author_dates = `git log origin/#{branch}..#{branch} --date=iso --pretty=format:"%ad"`.split("\n")
if $?
puts 'Probably, destination branch is not created or upstream info is not set'
exit false
end
author_dates.each do |date|
if OffTimeJp.off_time?(DateTime.parse(date))
puts 'Forbid pushing commits whose author date is in off time'
exit false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment