Last active
August 29, 2015 14:04
-
-
Save wusuopu/9f2a57571e527c0f7830 to your computer and use it in GitHub Desktop.
在Git commit之前检查所提交的文件是否有可执行权限。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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