Last active
April 19, 2019 14:00
-
-
Save apelliciari/de2f919b4112a359d5b277a7746c3e28 to your computer and use it in GitHub Desktop.
To walk every subdirectory checking if there is uncommitted code
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
#### USAGE: python walk-git ROOTDIR MAX_DEPTH | |
import os | |
import sys | |
import pprint | |
import subprocess | |
ROOTDIR = sys.argv[1] | |
MAX_DEPTH = sys.argv[2] | |
gitfolders = [] | |
for root, dirs, files in os.walk(ROOTDIR): | |
if root[len(ROOTDIR) + 1:].count(os.sep) < int(MAX_DEPTH): | |
for f in files: | |
if os.path.isdir(os.path.join(root, ".git")): | |
gitfolders.append(root) | |
gitfolders = set(gitfolders) | |
for gitfolder in gitfolders: | |
# git --git-dir /foo/bar/.git log | |
out_popen = subprocess.Popen(['git', 'status'], | |
cwd=gitfolder, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.STDOUT, | |
universal_newlines=True) | |
stdout,stderr = out_popen.communicate() | |
print("-"*80) | |
print("STATUS of {}:".format(gitfolder)) | |
print(stdout) | |
print(stderr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment