Skip to content

Instantly share code, notes, and snippets.

Created August 14, 2013 14:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Git some information about a repo if possible.
#!/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:
info = False
with open(os.path.join(repo_root, '.git', 'description')) as f:
name =[: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:
if info:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment