diff --git a/project_processor/gh_processor/github_downloader.py b/project_processor/gh_processor/github_downloader.py index 51ea2d7..242dfa3 100644 --- a/project_processor/gh_processor/github_downloader.py +++ b/project_processor/gh_processor/github_downloader.py @@ -27,8 +27,23 @@ def download_github_repo(repo_url: str, branch: str = "main") -> str: """ repo_name = repo_url.split("/")[-1].split(".")[0] repo_path = os.path.abspath(repo_name) + + if os.path.exists(repo_path): + repo = Repo(repo_path) + origin = repo.remote('origin') + + origin.fetch() + + head_ref = f"refs/remotes/origin/{branch}" + if repo.commit() != repo.commit(head_ref) or repo.is_dirty(untracked_files=True): + # Reset the local repository to match the last version on GitHub + repo.git.reset('--hard', 'HEAD') + logger.info(f"Repository {repo_name} is now synced with the last version on GitHub.") + else: + logger.info(f"Repository {repo_name} is already up-to-date.") + + else: + Repo.clone_from(repo_url, repo_name, branch=branch) + logger.info(f"Repository '{repo_name}' downloaded successfully!") - Repo.clone_from(repo_url, repo_name, branch=branch) - - logger.info(f"Repository '{repo_name}' downloaded successfully!") return repo_path