def git_clone(requires): from git import Repo if sys.platform != "win32": # Unfortunately for windows user, the following function # needs shell=True, which expose security risk. I would # rather not to trade it with its marginal benefit make_sure_git_is_available() moban_home = get_moban_home() mkdir_p(moban_home) for require in requires: repo_name = get_repo_name(require.git_url) local_repo_folder = os.path.join(moban_home, repo_name) if os.path.exists(local_repo_folder): reporter.report_git_pull(repo_name) repo = Repo(local_repo_folder) repo.git.pull() if require.reference: repo.git.checkout(require.reference) elif require.branch: repo.git.checkout(require.branch) if require.submodule: reporter.report_info_message("updating submodule") repo.git.submodule("update") else: reporter.report_git_clone(require.git_url) repo = Repo.clone_from(require.git_url, local_repo_folder, **require.clone_params()) if require.submodule: reporter.report_info_message("checking out submodule") repo.git.submodule("update", "--init")
def git_clone(repos, submodule=False): import subprocess moban_home = get_moban_home() mkdir_p(moban_home) for repo in repos: repo_name = get_repo_name(repo) local_repo_folder = os.path.join(moban_home, repo_name) current_working_dir = os.getcwd() if os.path.exists(local_repo_folder): reporter.report_git_pull(repo_name) os.chdir(local_repo_folder) subprocess.check_call(["git", "pull"]) if submodule: subprocess.check_call(["git", "submodule", "update"]) else: reporter.report_git_clone(repo_name) os.chdir(moban_home) subprocess.check_call(["git", "clone", repo, repo_name]) if submodule: os.chdir(os.path.join(moban_home, repo_name)) subprocess.check_call(["git", "submodule", "init"]) subprocess.check_call(["git", "submodule", "update"]) os.chdir(current_working_dir)
def git_clone(requires): from git import Repo moban_home = get_moban_home() mkdir_p(moban_home) for require in requires: repo_name = get_repo_name(require.git_url) local_repo_folder = os.path.join(moban_home, repo_name) if os.path.exists(local_repo_folder): reporter.report_git_pull(repo_name) repo = Repo(local_repo_folder) repo.git.pull() if require.submodule: reporter.report_info_message("updating submodule") repo.git.submodule("update") else: reporter.report_git_clone(require.git_url) repo = Repo.clone_from(require.git_url, local_repo_folder, **require.clone_params()) if require.submodule: reporter.report_info_message("checking out submodule") repo.git.submodule("update", "--init")