Skip to content

Instantly share code, notes, and snippets.

@maifeeulasad
Forked from neingeist/git-fsck-all
Last active June 24, 2020 11:12
Show Gist options
  • Save maifeeulasad/81539e1fd9eec7d41bb7c3cd0504d5c6 to your computer and use it in GitHub Desktop.
Save maifeeulasad/81539e1fd9eec7d41bb7c3cd0504d5c6 to your computer and use it in GitHub Desktop.
find all git repositories (and git working directories) starting from the current directory and perform a 'git fsck' on them.
import contextlib
import os
import subprocess
from datetime import datetime
# performing git fsck(file system check) seems slower, so I mane this hack
# still can be found on it's upstream or here : https://gist.github.com/neingeist/7d448e574e9da30b6bcd
def git_directories(startdir):
for dirpath, dirnames, _ in os.walk(startdir):
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)
def remote_v(directory):
file = open("config","r")
for line in file :
if ".git" in line:
print(line)
# add correct path for you - where you want to log your data
with open('D:\git_log.txt', 'a') as logfile:
#print(datetime.now())
logfile.write(directory+" -M- "+ str(datetime.now()) + " -M- "+line)
for git_directory in git_directories('.'):
with working_directory(git_directory):
print('\n{} : '.format(os.getcwd()))
remote_v(os.getcwd())
# it will produce some extra upstream location such as [lfs], [hooks], [and some submodule links]
'''
result looks something like this :
E:\gits\android-architecture-components\.git -M- 2020-06-23 11:19:09.463253 -M- url = https://github.com/maifeeulasad/android-architecture-components.git
E:\gits\android-viewmodel-databinding\.git -M- 2020-06-23 11:19:09.613164 -M- url = https://github.com/maifeeulasad/android-viewmodel-databinding.git
E:\gits\Android-Volume-Head\.git -M- 2020-06-23 11:19:09.820053 -M- url = https://github.com/maifeeulasad/Android-Volume-Head.git
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment