Skip to content

Remove feature to fetch upstream #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 5 additions & 42 deletions django_mongodb_cli/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
get_management_command,
get_repos,
repo_clone,
repo_fetch,
repo_install,
repo_status,
repo_update,
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
42 changes: 1 addition & 41 deletions django_mongodb_cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ 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",
"docs @ git+ssh://git@github.com/mongodb/docs@master",
"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",
]

Expand Down