Skip to content
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

Use 'git remote update' instead of multiple calls to 'git fetch' #4

Merged
merged 1 commit into from
Aug 2, 2022
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
2 changes: 1 addition & 1 deletion git_river/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main(ctx: click.Context) -> None:
main.add_command(git_river.commands.clone.main)
main.add_command(git_river.commands.config.main)
main.add_command(git_river.commands.forge.main)
main.add_command(git_river.commands.repo.fetch_remotes)
main.add_command(git_river.commands.repo.update_remotes)
main.add_command(git_river.commands.repo.merge_feature_branches)
main.add_command(git_river.commands.repo.tidy_branches)
main.add_command(git_river.commands.repo.rebase)
Expand Down
6 changes: 3 additions & 3 deletions git_river/commands/forge.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ def configure_remotes(workspace: RepositoryManager) -> None:
repo.configure_remotes()


@main.command(name="fetch")
@main.command(name="update")
@click.pass_obj
def fetch_remotes(workspace: RepositoryManager) -> None:
def update_remotes(workspace: RepositoryManager) -> None:
"""Fetch configured remotes for each repository."""
with git_river.ext.click.progressbar(
iterable=workspace.existing(),
Expand All @@ -218,7 +218,7 @@ def fetch_remotes(workspace: RepositoryManager) -> None:
logger_name=__name__,
) as progress:
for repo in progress:
repo.fetch_remotes()
repo.update_remotes()


@main.command(name="tidy")
Expand Down
12 changes: 6 additions & 6 deletions git_river/commands/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@
)


@click.command(name="fetch")
@click.command(name="update")
@click_repo_option
def fetch_remotes(path: pathlib.Path) -> None:
"""Fetch all remotes."""
git_river.repository.LocalRepository.from_path(path).fetch_remotes()
def update_remotes(path: pathlib.Path) -> None:
"""Update and prune all remotes."""
git_river.repository.LocalRepository.from_path(path).update_remotes()


@click.command(name="merge")
Expand Down Expand Up @@ -141,7 +141,7 @@ def tidy_branches(path: pathlib.Path, dry_run: bool, mainline: typing.Optional[s

mainline = repo.discover_mainline_branch(mainline)

repo.fetch_remotes(prune=True)
repo.update_remotes()
repo.remove_merged_branches(mainline, dry_run=dry_run)


Expand Down Expand Up @@ -195,7 +195,7 @@ def end(
repo.fetch_branch_from_remote(mainline, remote=upstream)
repo.switch_to_branch(mainline)
repo.remove_merged_branches(mainline, dry_run=False)
repo.fetch_remotes(prune=True)
repo.update_remotes()

if downstream := repo.discover_optional_downstream_remote(downstream):
repo.push_to_remote(mainline, remote=downstream)
9 changes: 4 additions & 5 deletions git_river/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,11 @@ def create_remote(self, name: str, url: str) -> None:
log.warning("Updating remote", remote=name, new={url}, old=set(remote.urls))
remote.set_url(url)

def fetch_remotes(self, prune: bool = True) -> None:
def update_remotes(self, prune: bool = True) -> None:
"""Update (and prune) all remotes using 'git remote update'."""
log = self.bind(logger)
log.info("Fetching remotes")
for remote in self.repo.remotes:
log.debug("Fetching remote", remote=remote.name)
remote.fetch(prune=prune, tags=True)
log.info("Updating remotes")
self.repo.git._call_process("remote", "update", insert_kwargs_after="update", prune=prune)

def remove_merged_branches(self, target: str, *, dry_run: bool = True) -> None:
"""Remove branches that have been merged into the repo's default branch."""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "git-river"
version = "1.3.1"
version = "1.4.0"
readme = "README.md"
description = "Tools for working with upstream repositories"
homepage = "https://pypi.org/project/git-river/"
Expand Down