Skip to content

Commit 55e1b10

Browse files
borntypingConan-Kudo
authored andcommitted
Use 'git remote update' instead of multiple calls to 'git fetch'
1 parent 88faaaa commit 55e1b10

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

git_river/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def main(ctx: click.Context) -> None:
4141
main.add_command(git_river.commands.clone.main)
4242
main.add_command(git_river.commands.config.main)
4343
main.add_command(git_river.commands.forge.main)
44-
main.add_command(git_river.commands.repo.fetch_remotes)
44+
main.add_command(git_river.commands.repo.update_remotes)
4545
main.add_command(git_river.commands.repo.merge_feature_branches)
4646
main.add_command(git_river.commands.repo.tidy_branches)
4747
main.add_command(git_river.commands.repo.rebase)

git_river/commands/forge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ def configure_remotes(workspace: RepositoryManager) -> None:
207207
repo.configure_remotes()
208208

209209

210-
@main.command(name="fetch")
210+
@main.command(name="update")
211211
@click.pass_obj
212-
def fetch_remotes(workspace: RepositoryManager) -> None:
212+
def update_remotes(workspace: RepositoryManager) -> None:
213213
"""Fetch configured remotes for each repository."""
214214
with git_river.ext.click.progressbar(
215215
iterable=workspace.existing(),
@@ -218,7 +218,7 @@ def fetch_remotes(workspace: RepositoryManager) -> None:
218218
logger_name=__name__,
219219
) as progress:
220220
for repo in progress:
221-
repo.fetch_remotes()
221+
repo.update_remotes()
222222

223223

224224
@main.command(name="tidy")

git_river/commands/repo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@
8989
)
9090

9191

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

9898

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

142142
mainline = repo.discover_mainline_branch(mainline)
143143

144-
repo.fetch_remotes(prune=True)
144+
repo.update_remotes()
145145
repo.remove_merged_branches(mainline, dry_run=dry_run)
146146

147147

@@ -195,7 +195,7 @@ def end(
195195
repo.fetch_branch_from_remote(mainline, remote=upstream)
196196
repo.switch_to_branch(mainline)
197197
repo.remove_merged_branches(mainline, dry_run=False)
198-
repo.fetch_remotes(prune=True)
198+
repo.update_remotes()
199199

200200
if downstream := repo.discover_optional_downstream_remote(downstream):
201201
repo.push_to_remote(mainline, remote=downstream)

git_river/repository.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,11 @@ def create_remote(self, name: str, url: str) -> None:
223223
log.warning("Updating remote", remote=name, new={url}, old=set(remote.urls))
224224
remote.set_url(url)
225225

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

233232
def remove_merged_branches(self, target: str, *, dry_run: bool = True) -> None:
234233
"""Remove branches that have been merged into the repo's default branch."""

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "git-river"
3-
version = "1.3.1"
3+
version = "1.4.0"
44
readme = "README.md"
55
description = "Tools for working with upstream repositories"
66
homepage = "https://pypi.org/project/git-river/"

0 commit comments

Comments
 (0)