Created
June 5, 2021 08:53
-
-
Save tommyjtl/487a781456a70b2bb8bc69f8e3ccaa8f to your computer and use it in GitHub Desktop.
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
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