You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB
Plaintext

9 years ago
#!/usr/bin/env python
"""
find all git repositories (and git working directories) starting from the
current directory and perform a 'git fsck' on them.
"""
from __future__ import division, print_function
from colorama import Fore
import contextlib
import os
import subprocess
def git_directories(startdir):
for dirpath, dirnames, _ in os.walk(startdir):
if '.sync' in dirpath:
continue
if '.git/modules' in dirpath:
# FIXME
continue
9 years ago
if set(['info', 'objects', 'refs']).issubset(set(dirnames)):
yield dirpath
@contextlib.contextmanager
def working_directory(directory):
saved_cwd = os.getcwd()
os.chdir(directory)
yield
os.chdir(saved_cwd)
for git_directory in git_directories('.'):
with working_directory(git_directory):
try:
subprocess.check_output(['git', 'fsck', '--no-dangling'], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
9 years ago
print((Fore.RED + 'git fsck is unhappy with {}' + Fore.RESET)
.format(git_directory))
print(e.output)