Skip to content

Instantly share code, notes, and snippets.

@matthewryanscott
Created May 23, 2011 00:15
Show Gist options
  • Save matthewryanscott/986037 to your computer and use it in GitHub Desktop.
Save matthewryanscott/986037 to your computer and use it in GitHub Desktop.
Inspect all sibling directories, and show current git revisions for each that is a git repo.
#!/usr/bin/env python2.6
"""Inspect all sibling directories, and show current git revisions for each that is a git repo."""
import re
import sys
import os
import subprocess
MODULE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
def is_git_path(path):
return os.path.isdir(os.path.join(path, '.git'))
def find_git_revision(path):
git_path = os.path.join(path, '.git')
p = subprocess.Popen(['git', '--git-dir={0}'.format(git_path), 'rev-parse', 'HEAD'], stdout=subprocess.PIPE)
stdout, stderr = p.communicate()
return stdout.strip()
def all_dirs(path):
for name in os.listdir(path):
inner_path = os.path.join(path, name)
if os.path.isdir(inner_path):
yield inner_path
def main(args):
for path in all_dirs(MODULE_PATH):
if is_git_path(path):
name = os.path.basename(path)
rev = find_git_revision(path)
print '{0:s}:{1:s}'.format(name, rev)
return 0
if __name__ == '__main__':
args = sys.argv[1:]
sys.exit(main(args))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment