Last active
August 29, 2015 14:01
-
-
Save avalanchy/0b815be8e5bfe8ecb149 to your computer and use it in GitHub Desktop.
GIT: Display branch url and check for PDB when pushing into remote repository. #python #git #git-hook
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 subprocess | |
import sys | |
def branch_url(): | |
remote = sys.argv[2] | |
command = 'git branch --contains' | |
branch_name = subprocess.check_output(command, shell=True).strip(' *\n') | |
tree_url = remote.replace(':', '/') \ | |
.replace('git@', 'https://') \ | |
.replace('.git', '/tree/') | |
branch_url = tree_url + branch_name | |
print 'Branch URL:\n * ' + branch_url | |
def pdb_in_code(): | |
command = 'grep -nIr --include=\\*.py pdb' | |
try: | |
output = subprocess.check_output(command, shell=True) | |
except subprocess.CalledProcessError: | |
pass | |
else: | |
print '!!! Pdb left in code' | |
print output.strip() | |
if __name__ == '__main__': | |
branch_url() | |
pdb_in_code() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment