Skip to content

Instantly share code, notes, and snippets.

@tommyjtl
Created June 5, 2021 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommyjtl/487a781456a70b2bb8bc69f8e3ccaa8f to your computer and use it in GitHub Desktop.
Save tommyjtl/487a781456a70b2bb8bc69f8e3ccaa8f to your computer and use it in GitHub Desktop.
import subprocess, os
current_path = os.getcwd()
current_file_list = os.listdir()
def exec_command(cmd):
command = cmd.split()
command_output = subprocess.run(command, capture_output=True)
for line in command_output.stdout.decode("utf-8").split("\n"):
print("\t\t", line)
for item in current_file_list:
if os.path.isdir(current_path + "/" + item) == True:
os.chdir(item)
command = ["git", "remote", "-v"]
command_output = subprocess.run(command, capture_output=True)
for line in command_output.stdout.decode("utf-8").split("\n"):
if "git.cocorobo.hk" in line:
print("\"" + item + "\"", "is a directory.")
command = "git remote set-url origin " + line.strip("origin").strip("(fetch)").strip("\t")
print("\t", "git reset --hard")
exec_command("git reset --hard")
print("\t", command.replace("cocorobo.hk", "cocorobo.cn"))
exec_command(command.replace("cocorobo.hk", "cocorobo.cn"))
print("\t", "git pull")
exec_command("git pull")
break
os.chdir(current_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment