Last active
November 22, 2017 17:12
-
-
Save austinmcconnell/fc4ed9676cbf1d0cbcca54ea565dc847 to your computer and use it in GitHub Desktop.
Simple python script to reinitialize all git repositories nested one level under a "projects" folder. Primarily this is useful to "upgrade" global hooks in a ~/.git-templates folder as git init will not overwrite any existing file.
This file contains 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
from pathlib import Path | |
import subprocess | |
CURRENT_DIR = Path('.') | |
projects = sorted([x for x in CURRENT_DIR.iterdir() if x.is_dir()]) | |
for project in projects: | |
print('*' * 70) | |
print(f'Checking project: {project}') | |
print('*' * 70) | |
git_dir = project / '.git' | |
if not git_dir.exists(): | |
print('Not a git repo. Skipping...') | |
continue | |
hooks_dir = git_dir / 'hooks' | |
hooks = [x for x in hooks_dir.iterdir() if x.is_file()] | |
for hook in hooks: | |
print(f'Removing hook: {hook.name}') | |
hook.unlink() | |
subprocess.run(['git', 'init'], cwd=project) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment