Skip to content

Instantly share code, notes, and snippets.

@wusuopu
Last active August 29, 2015 14:04
Show Gist options
  • Save wusuopu/9f2a57571e527c0f7830 to your computer and use it in GitHub Desktop.
Save wusuopu/9f2a57571e527c0f7830 to your computer and use it in GitHub Desktop.
在Git commit之前检查所提交的文件是否有可执行权限。
#!/usr/bin/env ruby
#-*- coding:utf-8 -*-
# gem install rugged
require "rugged"
repo = Rugged::Repository.discover Dir.pwd
file_list = []
ext_list = [".png", ".jpg"]
repo.status do |f, s|
if s.include?(:index_new) || s.include?(:index_modified) then
if ext_list.include?(File.extname(f)) then
file_list.push f
end
end
end
file_list.each do |f|
s = File.stat f
if s.file? && s.mode & 0111 != 0 then
puts "file '#{f}' is executable!"
exit 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment