Last active
September 3, 2022 02:22
-
-
Save vkhazin/0ef5cc603bfc794b45518c6f12e3ffca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Place the file in the root folder of git repos to sync | |
# Run the script: python3 ./git-pull-push.py source_remote target_remote branch_name | |
import os | |
import sys | |
errors = [] | |
def main(): | |
source_remote = sys.argv[1] | |
target_remote_= sys.argv[2] | |
branch = sys.argv[3] | |
start_dir = './' | |
dirs = [ name for name in os.listdir(start_dir) if os.path.isdir(os.path.join(start_dir, name)) ] | |
print(f'directories: {dirs}') | |
for dir in dirs: | |
error = sync_remotes(dir=dir, source_remote=source_remote, target_remote=target_remote_, branch=branch) | |
if error: | |
errors.append(f'Dir: {dir}, Error: {error}') | |
if (len(errors) > 0): | |
print(f'Errors encountered: {errors}') | |
def sync_remotes(dir, source_remote, target_remote, branch): | |
print(f'Processing {dir}...') | |
cmd = f'cd ./{dir} && git checkout {branch} && git pull {source_remote} {branch} && git pull {target_remote} {branch} && git push {target_remote} {branch}' | |
out = os.popen(cmd).read() | |
print(out) | |
print(f'Completed {dir}!\n') | |
if (out.lower().find('fatal') > -1) or (out.lower().find('conflict') > -1): | |
return out | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment