From 1ed94f6a5d9aaa7c1d740a023cb62b4053c00788 Mon Sep 17 00:00:00 2001 From: "Jeffrey A. Clark" Date: Mon, 7 Apr 2025 16:00:44 -0400 Subject: [PATCH] Remove feature to fetch upstream --- django_mongodb_cli/repo.py | 47 ++++--------------------------------- django_mongodb_cli/utils.py | 42 +-------------------------------- pyproject.toml | 16 ++++++------- 3 files changed, 14 insertions(+), 91 deletions(-) diff --git a/django_mongodb_cli/repo.py b/django_mongodb_cli/repo.py index 649add1..907b21f 100644 --- a/django_mongodb_cli/repo.py +++ b/django_mongodb_cli/repo.py @@ -10,7 +10,6 @@ get_management_command, get_repos, repo_clone, - repo_fetch, repo_install, repo_status, repo_update, @@ -45,7 +44,7 @@ def repo(ctx, list_repos): Run Django fork and third-party library tests. """ ctx.obj = Repo() - repos, url_pattern, branch_pattern, upstream_pattern = get_repos("pyproject.toml") + repos, url_pattern, branch_pattern = get_repos("pyproject.toml") if list_repos: for repo_entry in repos: click.echo(repo_entry) @@ -70,7 +69,7 @@ def repo(ctx, list_repos): @pass_repo def clone(repo, ctx, repo_names, all_repos, install): """Clone repositories from `pyproject.toml`.""" - repos, url_pattern, branch_pattern, upstream_pattern = get_repos("pyproject.toml") + repos, url_pattern, branch_pattern = get_repos("pyproject.toml") if repo_names: for repo_name in repo_names: @@ -123,9 +122,7 @@ def install(repo, ctx, repo_names, all_repos): return if all_repos: - repos, url_pattern, branch_pattern, upstream_pattern = get_repos( - "pyproject.toml" - ) + repos, url_pattern, branch_pattern = get_repos("pyproject.toml") for repo_entry in repos: url_match = url_pattern.search(repo_entry) if url_match: @@ -140,40 +137,6 @@ def install(repo, ctx, repo_names, all_repos): click.echo(ctx.get_help()) -@repo.command() -@click.argument("repo_names", nargs=-1) -@click.option( - "-a", - "--all-repos", - is_flag=True, -) -@click.pass_context -@pass_repo -def fetch(repo, ctx, repo_names, all_repos): - """Add and fetch upstream remotes for cloned repositories.""" - repos, url_pattern, _, upstream_pattern = get_repos("pyproject.toml") - if repo_names: - for repo_name in repo_names: - click.echo(f"Fetching upstream for {repo_name}...") - for repo_entry in repos: - if ( - os.path.basename(url_pattern.search(repo_entry).group(0)) - == repo_name - ): - repo_fetch(repo_entry, upstream_pattern, url_pattern, repo) - click.echo(f"Repository '{repo_name}' not found.") - return - - if all_repos: - click.echo(f"Fetching upstream remotes for {len(repos)} repositories...") - for repo_entry in repos: - repo_fetch(repo_entry, upstream_pattern, url_pattern, repo) - return - - if ctx.args == []: - click.echo(ctx.get_help()) - - @repo.command() @click.argument("repo_names", nargs=-1) @click.option( @@ -218,7 +181,7 @@ def makemigrations( ): """Run `makemigrations` for cloned repositories.""" - repos, url_pattern, branch_pattern, upstream_pattern = get_repos("pyproject.toml") + repos, url_pattern, branch_pattern = get_repos("pyproject.toml") if repo_name: for repo_entry in repos: url_match = url_pattern.search(repo_entry) @@ -291,7 +254,7 @@ def test( """ Run tests for Django fork and third-party libraries. """ - repos, url_pattern, branch_pattern, upstream_pattern = get_repos("pyproject.toml") + repos, url_pattern, branch_pattern = get_repos("pyproject.toml") if repo_name: # Show test settings if show: diff --git a/django_mongodb_cli/utils.py b/django_mongodb_cli/utils.py index 877244b..87b94d9 100644 --- a/django_mongodb_cli/utils.py +++ b/django_mongodb_cli/utils.py @@ -100,8 +100,7 @@ def get_repos(pyproject_path): branch_pattern = re.compile( r"git\+ssh://git@github\.com/[^/]+/[^@]+@([a-zA-Z0-9_\-\.]+)\b" ) - upstream_pattern = re.compile(r"#\s*upstream:\s*([\w-]+)") - return repos, url_pattern, branch_pattern, upstream_pattern + return repos, url_pattern, branch_pattern def repo_clone(repo_entry, url_pattern, branch_pattern, repo): @@ -154,45 +153,6 @@ def repo_install(clone_path): ) -def repo_fetch(repo_entry, upstream_pattern, url_pattern, repo): - """Helper function to fetch upstream remotes for a repository.""" - url_match = url_pattern.search(repo_entry) - upstream_match = upstream_pattern.search(repo_entry) - - if not url_match or not upstream_match: - return - - repo_url = url_match.group(0) - repo_name = os.path.basename(repo_url) - clone_path = os.path.join(repo.home, repo_name) - - if os.path.exists(clone_path): - click.echo(f"Adding upstream remote for {repo_name}...") - remote = f"https://github.com/{upstream_match.group(1)}/{repo_name}" - if os.path.exists(clone_path): - repo = git.Repo(clone_path) - try: - repo.create_remote("upstream", remote) - click.echo(click.style(f"Added remote {remote}", fg="green")) - except git.exc.GitCommandError: - click.echo( - click.style( - f"Remote {repo.remotes.upstream.name} exists! {repo.remotes.upstream.url}", - fg="yellow", - ) - ) - repo.remotes.upstream.fetch() - try: - repo.git.rebase("upstream/main") - click.echo(click.style(f"Rebased {repo_name}", fg="green")) - except git.exc.GitCommandError: - click.echo(click.style(f"Failed to rebase {repo_name}", fg="red")) - else: - click.echo(click.style(f"Skipping {remote}", fg="yellow")) - else: - click.echo(f"Skipping {repo_name}: Repository not found at {clone_path}") - - def repo_update(repo_entry, url_pattern, repo): """Helper function to update a single repository.""" url_match = url_pattern.search(repo_entry) diff --git a/pyproject.toml b/pyproject.toml index a71db13..f784b6d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,11 +35,11 @@ packages = ["django_mongodb_cli"] dev = [ "django-allauth @ git+ssh://git@github.com/pennersr/django-allauth@main", "django-debug-toolbar @ git+ssh://git@github.com/django-commons/django-debug-toolbar@main", - "django-filter @ git+ssh://git@github.com/aclark4life/django-filter@main # upstream: carltongibson", - "django-mongodb-app @ git+ssh://git@github.com/aclark4life/django-mongodb-app@5.1.x # upstream: mongodb-labs", - "django-mongodb-backend @ git+ssh://git@github.com/aclark4life/django-mongodb-backend@main # upstream: mongodb", - "django-mongodb-extensions @ git+ssh://git@github.com/aclark4life/django-mongodb-extensions@main", - "django-mongodb-project @ git+ssh://git@github.com/aclark4life/django-mongodb-project@5.1.x # upstream: mongodb-labs", + "django-filter @ git+ssh://git@github.com/carltongibson/django-filter@main", + "django-mongodb-app @ git+ssh://git@github.com/mongodb-labs/django-mongodb-app@5.1.x", + "django-mongodb-backend @ git+ssh://git@github.com/mongodb/django-mongodb-backend@main", + "django-mongodb-extensions @ git+ssh://git@github.com/mongodb-labs/django-mongodb-extensions@main", + "django-mongodb-project @ git+ssh://git@github.com/mongodb-labs/django-mongodb-project@5.1.x", "django-mongodb-templates @ git+ssh://git@github.com/aclark4life/django-mongodb-templates@main", "django-rest-framework @ git+ssh://git@github.com/encode/django-rest-framework@main", "django @ git+ssh://git@github.com/mongodb-forks/django@mongodb-5.1.x", @@ -47,9 +47,9 @@ dev = [ "flask-pymongo @ git+ssh://git@github.com/mongodb-labs/flask-pymongo", "DublinCityCenterPubFinder @ git+ssh://git@github.com/anaiyaraisin/DublinCityCenterPubFinder", "langchain-mongodb @ git+ssh://git@github.com/langchain-ai/langchain-mongodb@main", - "mongo-python-driver @ git+ssh://git@github.com/aclark4life/mongo-python-driver@master # upstream: mongodb", - "wagtail-mongodb-project @ git+ssh://git@github.com/aclark4life/wagtail-mongodb-project@main", - "wagtail @ git+ssh://git@github.com/aclark4life/wagtail@main # upstream: mongodb-forks", + "mongo-python-driver @ git+ssh://git@github.com/mongodb/mongo-python-driver@master", + "wagtail-mongodb-project @ git+ssh://git@github.com/mongodb-labs/wagtail-mongodb-project@main", + "wagtail @ git+ssh://git@github.com/mongodb-forks/wagtail@main", "xmlsec @ git+ssh://git@github.com/xmlsec/python-xmlsec@main", ]