MCPcopy Index your code
hub / github.com/FSoft-AI4Code/HyperAgent / clone_repo

Function clone_repo

src/hyperagent/utils.py:61–88  ·  view source on GitHub ↗

Clones a GitHub repository to a specified directory. Args: repo (str): The GitHub repository to clone. commit (str): The commit to checkout. root_dir (str): The root directory to clone the repository to. token (str): The GitHub personal access token to use f

(repo, commit, root_dir, token, logger)

Source from the content-addressed store, hash-verified

59 return python_path
60
61def clone_repo(repo, commit, root_dir, token, logger):
62 """
63 Clones a GitHub repository to a specified directory.
64
65 Args:
66 repo (str): The GitHub repository to clone.
67 commit (str): The commit to checkout.
68 root_dir (str): The root directory to clone the repository to.
69 token (str): The GitHub personal access token to use for authentication.
70
71 Returns:
72 Path: The path to the cloned repository directory.
73 """
74 repo_dir = Path(root_dir, f"repo__{repo.replace('/', '__')}__commit__{commit}")
75
76 if not repo_dir.exists():
77 repo_url = f"https://{token}@github.com/{repo}.git"
78 # logger.info(f"Cloning {repo} {os.getpid()}")
79 Repo.clone_from(repo_url, repo_dir)
80 cmd = f"cd {repo_dir} && git reset --hard {commit} && git clean -fdxq"
81 subprocess.run(
82 cmd,
83 shell=True,
84 check=True,
85 stdout=subprocess.DEVNULL,
86 stderr=subprocess.DEVNULL,
87 )
88 return root_dir + "/" + repo_dir.name
89
90def identify_extension(language):
91 """

Callers 2

SetupFunction · 0.90
setupFunction · 0.90

Calls 2

replaceMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected