mirror of
				https://gitee.com/coder-xiaomo/gitee2github
				synced 2025-11-04 14:23:10 +08:00 
			
		
		
		
	运行前增加.git检查,避免造成Git仓库混乱;优化GitHub账号授权提示信息;优化最后命令执行部分逻辑
This commit is contained in:
		@@ -4,14 +4,14 @@ import time
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def githubOauth(GitHubClientID, GitHubClientSecret, githubProxies, timeout):
 | 
					def githubOauth(GitHubClientID, GitHubClientSecret, githubProxies, timeout):
 | 
				
			||||||
    print("################################ GitHub 授权 ################################")
 | 
					    print("################################ GitHub 授权 ################################")
 | 
				
			||||||
    input("按回车开始进行GitHub账号授权:")
 | 
					    input("按回车开始进行GitHub账号授权,注意如果账号Organization中的仓库也需要同步,那么您点击Authorize绿色按钮前需要点击Organization access部分对应组织的Grant按钮:")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # ######################################## 获取GitHub用户的 access_token ########################################
 | 
					    # ######################################## 获取GitHub用户的 access_token ########################################
 | 
				
			||||||
    # Api文档:
 | 
					    # Api文档:
 | 
				
			||||||
    # https://docs.github.com/cn/developers/apps/building-oauth-apps/authorizing-oauth-apps
 | 
					    # https://docs.github.com/cn/developers/apps/building-oauth-apps/authorizing-oauth-apps
 | 
				
			||||||
    # https://docs.github.com/cn/developers/apps/building-oauth-apps/scopes-for-oauth-apps
 | 
					    # https://docs.github.com/cn/developers/apps/building-oauth-apps/scopes-for-oauth-apps
 | 
				
			||||||
    # 认证地址
 | 
					    # 认证地址
 | 
				
			||||||
    oauth_url = 'https://github.com/login/oauth/authorize?client_id={ClientID}&redirect_uri={redirect_uri}&response_type=code&scope=user,repo' \
 | 
					    oauth_url = 'https://github.com/login/oauth/authorize?client_id={ClientID}&redirect_uri={redirect_uri}&response_type=code&scope=user repo' \
 | 
				
			||||||
        .format(ClientID=GitHubClientID, redirect_uri='https://www.only4.work/appHelper/github_show_code_param.php')
 | 
					        .format(ClientID=GitHubClientID, redirect_uri='https://www.only4.work/appHelper/github_show_code_param.php')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # 打开浏览器让用户授权
 | 
					    # 打开浏览器让用户授权
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,6 +11,18 @@ def prepareWorkingDir(CurrentDir, WorkingDir):
 | 
				
			|||||||
    print("工作目录", WorkingDir)
 | 
					    print("工作目录", WorkingDir)
 | 
				
			||||||
    # print(os.getcwd()) # 获取当前脚本运行目录
 | 
					    # print(os.getcwd()) # 获取当前脚本运行目录
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if os.path.exists(os.path.abspath(CurrentDir + "/.git")):
 | 
				
			||||||
 | 
					        print("\033[1;37;41m[error] 请不要在Git仓库中运行本程序,否则会导致Git仓库嵌套,当前仓库代码会覆盖您的仓库!\033[0m")
 | 
				
			||||||
 | 
					        print("[error] 继续操作前请删除当前目录下的 .git 隐藏文件夹", os.path.abspath(CurrentDir + "/.git"))
 | 
				
			||||||
 | 
					        print()
 | 
				
			||||||
 | 
					        print("您可使用以下命令进行删除:")
 | 
				
			||||||
 | 
					        print("Linux系统")
 | 
				
			||||||
 | 
					        print('rm -rf "{}"'.format(os.path.abspath(CurrentDir + "/.git")))
 | 
				
			||||||
 | 
					        print("Windows系统")
 | 
				
			||||||
 | 
					        print('rd /s /q "{}"'.format(os.path.abspath(CurrentDir + "/.git")))
 | 
				
			||||||
 | 
					        print("\033[1;37;41m以上命令为强制删除命令,请再三确认无误后再进行操作!\033[0m")
 | 
				
			||||||
 | 
					        exit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if os.path.exists(WorkingDir):
 | 
					    if os.path.exists(WorkingDir):
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
        # # 工作目录已存在,如果非空就创建
 | 
					        # # 工作目录已存在,如果非空就创建
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,7 +19,7 @@ def transferRepos(matchList, WorkingDir, fromRepoProtocol = 'https', toRepoProto
 | 
				
			|||||||
    for repo in matchList:
 | 
					    for repo in matchList:
 | 
				
			||||||
        # 查看当前目录
 | 
					        # 查看当前目录
 | 
				
			||||||
        # commands.append('echo 当前目录')
 | 
					        # commands.append('echo 当前目录')
 | 
				
			||||||
        # commands.append('chdir')
 | 
					        commands.append('chdir')
 | 
				
			||||||
        # 克隆仓库
 | 
					        # 克隆仓库
 | 
				
			||||||
        localRepoFolder = repo['from']['full_name'].split('/')[-1] + ".git"
 | 
					        localRepoFolder = repo['from']['full_name'].split('/')[-1] + ".git"
 | 
				
			||||||
        if not os.path.exists(WorkingDir + "/" + localRepoFolder):
 | 
					        if not os.path.exists(WorkingDir + "/" + localRepoFolder):
 | 
				
			||||||
@@ -32,6 +32,7 @@ def transferRepos(matchList, WorkingDir, fromRepoProtocol = 'https', toRepoProto
 | 
				
			|||||||
        # 切换到仓库目录
 | 
					        # 切换到仓库目录
 | 
				
			||||||
        # commands.append('echo 切换到仓库目录')
 | 
					        # commands.append('echo 切换到仓库目录')
 | 
				
			||||||
        commands.append("cd {folder_name}".format(folder_name = localRepoFolder))
 | 
					        commands.append("cd {folder_name}".format(folder_name = localRepoFolder))
 | 
				
			||||||
 | 
					        commands.append('chdir')
 | 
				
			||||||
        # 更新本地仓库
 | 
					        # 更新本地仓库
 | 
				
			||||||
        # 不可以使用 git fetch --all  如果仓库中有hidden ref,则推送时会报错
 | 
					        # 不可以使用 git fetch --all  如果仓库中有hidden ref,则推送时会报错
 | 
				
			||||||
        # commands.append('echo 更新本地仓库')
 | 
					        # commands.append('echo 更新本地仓库')
 | 
				
			||||||
@@ -61,17 +62,20 @@ def transferRepos(matchList, WorkingDir, fromRepoProtocol = 'https', toRepoProto
 | 
				
			|||||||
    print("\033[1;37;41m继续前请务全量必备份仓库!\033[0m")
 | 
					    print("\033[1;37;41m继续前请务全量必备份仓库!\033[0m")
 | 
				
			||||||
    print("\033[1;37;41m继续前请务全量必备份仓库!\033[0m")
 | 
					    print("\033[1;37;41m继续前请务全量必备份仓库!\033[0m")
 | 
				
			||||||
    print("\033[1;37;41m继续前请务全量必备份仓库!\033[0m")
 | 
					    print("\033[1;37;41m继续前请务全量必备份仓库!\033[0m")
 | 
				
			||||||
    print("继续操作代表您已阅读上述内容,程序将在工作目录下生成一个批处理脚本")
 | 
					    input("继续操作代表您已阅读上述内容,按回车键继续...")
 | 
				
			||||||
    if input("按<回车>键继续,或输入run直接执行(不推荐): ") == "run":
 | 
					
 | 
				
			||||||
        for commandForExecute in commands:
 | 
					    batFilePath = os.path.abspath(WorkingDir + "/commands.bat")
 | 
				
			||||||
            print("[正在执行]", commandForExecute)
 | 
					    f=open(batFilePath, "w")
 | 
				
			||||||
            os.system(commandForExecute)
 | 
					    f.write('\n'.join(commands))
 | 
				
			||||||
    else:
 | 
					    f.close()
 | 
				
			||||||
        commandTxtPath = os.path.abspath(WorkingDir + "/commands.bat")
 | 
					    print("命令文件生成完毕,请查看:", batFilePath)
 | 
				
			||||||
        f=open(commandTxtPath, "w")
 | 
					
 | 
				
			||||||
        f.write('\n'.join(commands))
 | 
					    if input("是否直接执行(不推荐)?输入y执行,其他输入不执行并继续: ") == "y":
 | 
				
			||||||
        f.close()
 | 
					        os.system(batFilePath)
 | 
				
			||||||
        print("命令文件生成完毕,请查看:", commandTxtPath)
 | 
					        # 下面这样执行不行,无法保证当前目录
 | 
				
			||||||
 | 
					        # for commandForExecute in commands:
 | 
				
			||||||
 | 
					        #     print("[正在执行]", commandForExecute)
 | 
				
			||||||
 | 
					        #     os.system(commandForExecute)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # for command in commands:
 | 
					    # for command in commands:
 | 
				
			||||||
    #     print(command)
 | 
					    #     print(command)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user