Git some information about a repo if possible.
This file contains 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 python | |
import subprocess | |
import os | |
F_DEVNULL = open(os.devnull, 'w') | |
p = subprocess.Popen(["git", "rev-parse", "--show-toplevel"], | |
stdout=subprocess.PIPE, stderr=F_DEVNULL) | |
repo_root, err = p.communicate() | |
repo_root = repo_root.strip() | |
if not repo_root: | |
print("(Non-git)") | |
exit() | |
info = False | |
try: | |
with open(os.path.join(repo_root, '.git', 'description')) as f: | |
name = f.read()[:35].strip() | |
p = subprocess.Popen(["git", "rev-parse", "--abbrev-ref", "HEAD"], | |
stdout=subprocess.PIPE, stderr=F_DEVNULL) | |
branch, err = p.communicate() | |
branch = branch.strip() | |
info = "%s (%s)" % (name, branch) | |
except IOError: | |
pass | |
if info: | |
print(info) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment