|
|
|
#!/usr/bin/env python3
|
|
|
|
"""show dirty git repos"""
|
|
|
|
|
|
|
|
from __future__ import division, print_function
|
|
|
|
|
|
|
|
from colorama import Fore
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import contextlib
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
# TODO config file (and defaults here)
|
|
|
|
IGNORES = [
|
|
|
|
r"\.sync",
|
|
|
|
r"\.git/modules", # XXX check this again
|
|
|
|
r"\.local/share/containers/storage",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def git_directories(startdir) -> Path:
|
|
|
|
for dirpath, dirnames, _ in os.walk(startdir):
|
|
|
|
if any(re.search(ignore, dirpath) for ignore in IGNORES):
|
|
|
|
continue
|
|
|
|
if set(['info', 'objects', 'refs']).issubset(set(dirnames)):
|
|
|
|
yield Path(dirpath)
|
|
|
|
|
|
|
|
|
|
|
|
@contextlib.contextmanager
|
|
|
|
def working_directory(directory: Path):
|
|
|
|
saved_cwd = os.getcwd()
|
|
|
|
os.chdir(directory)
|
|
|
|
yield
|
|
|
|
os.chdir(saved_cwd)
|
|
|
|
|
|
|
|
|
|
|
|
for git_directory in git_directories('.'):
|
|
|
|
# technically,we could have a different GIT_DIR than ".git", but this script
|
|
|
|
# assumes ".git".
|
|
|
|
if git_directory.parts[-1] != ".git":
|
|
|
|
continue
|
|
|
|
work_tree_directory = git_directory.parent
|
|
|
|
|
|
|
|
with working_directory(work_tree_directory):
|
|
|
|
try:
|
|
|
|
out = subprocess.check_output(['git', 'status', '-s'], stderr=subprocess.STDOUT)
|
|
|
|
if len(out) > 0:
|
|
|
|
print('== {}\n{}'.format(work_tree_directory, out.decode('utf-8')))
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print((Fore.RED + 'git status is unhappy with {}' + Fore.RESET)
|
|
|
|
.format(work_tree_directory))
|
|
|
|
print(e.output)
|