Skip to content

Instantly share code, notes, and snippets.

@dgrant
Last active December 14, 2015 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgrant/5159042 to your computer and use it in GitHub Desktop.
Save dgrant/5159042 to your computer and use it in GitHub Desktop.
Find any VCS directories in the specified path (ie. git, mercurial, svn, CVS)
#!/usr/bin/env python3
"""
Find all the VCS controlled directories in a file path
"""
import argparse
import os
EXTS = ['.git', '.hg', '.svn', 'CVS']
def find(path):
""" Find all VCS dirs in specified path """
found_roots = []
for root, dirs, _, in os.walk(path):
for folder in dirs:
if folder in EXTS:
# We've seen a matching dir
# See if we already found a parent
for found_root in found_roots:
if root.find(found_root) == 0:
break
else:
found_roots.append(root)
for root in found_roots:
print(root)
def main():
"""Main function"""
parser = argparse.ArgumentParser()
parser.add_argument('path', help='path to search for VCS dirs')
args = parser.parse_args()
find(args.path)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment