🐛 git-status-all: get working tree directory via pathlib

master
neingeist 2 years ago
parent 109fc110c1
commit a295c5c0c6

@ -4,13 +4,14 @@
from __future__ import division, print_function from __future__ import division, print_function
from colorama import Fore from colorama import Fore
from pathlib import Path
import contextlib import contextlib
import os import os
import subprocess import subprocess
def git_directories(startdir): def git_directories(startdir) -> Path:
for dirpath, dirnames, _ in os.walk(startdir): for dirpath, dirnames, _ in os.walk(startdir):
if '.sync' in dirpath: if '.sync' in dirpath:
continue continue
@ -18,11 +19,11 @@ def git_directories(startdir):
# FIXME # FIXME
continue continue
if set(['info', 'objects', 'refs']).issubset(set(dirnames)): if set(['info', 'objects', 'refs']).issubset(set(dirnames)):
yield dirpath yield Path(dirpath)
@contextlib.contextmanager @contextlib.contextmanager
def working_directory(directory): def working_directory(directory: Path):
saved_cwd = os.getcwd() saved_cwd = os.getcwd()
os.chdir(directory) os.chdir(directory)
yield yield
@ -30,7 +31,12 @@ def working_directory(directory):
for git_directory in git_directories('.'): for git_directory in git_directories('.'):
work_tree_directory = git_directory[:-4] # 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): with working_directory(work_tree_directory):
try: try:
out = subprocess.check_output(['git', 'status', '-s'], stderr=subprocess.STDOUT) out = subprocess.check_output(['git', 'status', '-s'], stderr=subprocess.STDOUT)

Loading…
Cancel
Save