Created
July 15, 2017 04:27
-
-
Save perrie625/ce7c2f4acc3bcd15d876ebb44f93e736 to your computer and use it in GitHub Desktop.
python pre-receive for check same blob object
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/python | |
import sys | |
import subprocess | |
data = sys.stdin.read() | |
_, new_obj, _ = data.split() | |
def command_output(command): | |
output = subprocess.check_output( | |
command, shell=True).split("\n") | |
result = [l.strip() for l in output if l] | |
return result | |
# get all blob-objects in new_obj | |
cmd = "git ls-tree -r %s" % new_obj | |
new_blobs = command_output(cmd) | |
new_shas = [b.split(" ")[2].split("\t")[0] for b in new_blobs] | |
# check if have same blob objects | |
if len(set(new_shas)) < len(new_shas): | |
print "reject" | |
sys.exit(1) | |
print "accept" | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment