Skip to content

Commit 8c96998

Browse files
committed
cmd,sync(refactor[API]): Rename parameters and methods for consistency
why: Follow Python community conventions (Django/pytest/Sphinx patterns) for clearer, more self-documenting APIs. what: - cmd/git.py: Rename _all parameters to descriptive names: - clone(_all) → all_branches - fetch(_all) → all_remotes - pull(_all) → all_remotes - help(_all) → show_all - rev_list(_all) → include_all_refs - get_url(_all) → all_urls - stash.save(_all) → include_ignored - stash.push(_all) → include_ignored - branch.ls(_all) → all_branches - sync/git.py: Add get_ prefix to getter methods: - remotes() → get_remotes() - remote() → get_remote() - Update all tests to use new API names
1 parent 301dffe commit 8c96998

4 files changed

Lines changed: 63 additions & 61 deletions

File tree

‎src/libvcs/cmd/git.py‎

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def clone(
346346
jobs: str | None = None,
347347
force: bool | None = None,
348348
local: bool | None = None,
349-
_all: bool | None = None,
349+
all_branches: bool | None = None,
350350
no_hardlinks: bool | None = None,
351351
hardlinks: bool | None = None,
352352
shared: bool | None = None,
@@ -481,7 +481,7 @@ def fetch(
481481
recurse_submodules: bool | t.Literal["yes", "on-demand", "no"] | None = None,
482482
recurse_submodules_default: bool | t.Literal["yes", "on-demand"] | None = None,
483483
submodule_prefix: StrOrBytesPath | None = None,
484-
_all: bool | None = None,
484+
all_remotes: bool | None = None,
485485
force: bool | None = None,
486486
keep: bool | None = None,
487487
multiple: bool | None = None,
@@ -574,7 +574,7 @@ def fetch(
574574
local_flags.append("--progress")
575575
if verbose:
576576
local_flags.append("--verbose")
577-
if _all:
577+
if all_remotes:
578578
local_flags.append("--all")
579579
if atomic:
580580
local_flags.append("--atomic")
@@ -903,7 +903,7 @@ def pull(
903903
#
904904
fetch: bool | None = None,
905905
no_fetch: bool | None = None,
906-
_all: bool | None = None,
906+
all_remotes: bool | None = None,
907907
force: bool | None = None,
908908
keep: bool | None = None,
909909
multiple: bool | None = None,
@@ -1079,7 +1079,7 @@ def pull(
10791079
local_flags.append("--progress")
10801080
if verbose:
10811081
local_flags.append("--verbose")
1082-
if _all:
1082+
if all_remotes:
10831083
local_flags.append("--all")
10841084
if atomic:
10851085
local_flags.append("--atomic")
@@ -1393,7 +1393,7 @@ def init(
13931393
def help(
13941394
self,
13951395
*,
1396-
_all: bool | None = None,
1396+
show_all: bool | None = None,
13971397
verbose: bool | None = None,
13981398
no_external_commands: bool | None = None,
13991399
no_aliases: bool | None = None,
@@ -1410,17 +1410,17 @@ def help(
14101410
14111411
Parameters
14121412
----------
1413-
_all : bool
1413+
show_all : bool
14141414
Prints everything.
14151415
14161416
no_external_commands : bool
1417-
For use with ``all``, excludes external commands.
1417+
For use with ``show_all``, excludes external commands.
14181418
14191419
no_aliases : bool
1420-
For use with ``all``, excludes aliases.
1420+
For use with ``show_all``, excludes aliases.
14211421
14221422
verbose : bool
1423-
For us with ``all``, on by default.
1423+
For us with ``show_all``, on by default.
14241424
14251425
config : bool
14261426
List all config vars.
@@ -1444,7 +1444,7 @@ def help(
14441444
>>> git.help()
14451445
"usage: git [...--version] [...--help] [-C <path>]..."
14461446
1447-
>>> git.help(_all=True)
1447+
>>> git.help(show_all=True)
14481448
"See 'git help <command>' to read about a specific subcommand..."
14491449
14501450
>>> git.help(info=True)
@@ -1457,7 +1457,7 @@ def help(
14571457

14581458
if verbose is True:
14591459
local_flags.append("--verbose")
1460-
if _all is True:
1460+
if show_all is True:
14611461
local_flags.append("--all")
14621462
if no_external_commands is True:
14631463
local_flags.append("--no-external-commands")
@@ -2162,7 +2162,7 @@ def rev_list(
21622162
first_parent: bool | None = None,
21632163
exclude_first_parent_only: bool | None = None,
21642164
_not: bool | None = None,
2165-
_all: bool | None = None,
2165+
include_all_refs: bool | None = None,
21662166
branches: str | bool | None = None,
21672167
tags: str | bool | None = None,
21682168
remotes: str | bool | None = None,
@@ -2220,7 +2220,9 @@ def rev_list(
22202220
>>> git.rev_list(commit="HEAD", path=".", max_count=1, header=True)
22212221
'...'
22222222
2223-
>>> git.rev_list(commit="origin..HEAD", max_count=1, _all=True, header=True)
2223+
>>> git.rev_list(
2224+
... commit="origin..HEAD", max_count=1, include_all_refs=True, header=True
2225+
... )
22242226
'...'
22252227
22262228
>>> git.rev_list(commit="origin..HEAD", max_count=1, header=True)
@@ -2277,7 +2279,7 @@ def rev_list(
22772279

22782280
for flag, shell_flag in [
22792281
# Limiting output
2280-
(_all, "--all"),
2282+
(include_all_refs, "--all"),
22812283
(author, "--author"),
22822284
(committer, "--committer"),
22832285
(grep, "--grep"),
@@ -2296,7 +2298,7 @@ def rev_list(
22962298
(first_parent, "--first-parent"),
22972299
(exclude_first_parent_only, "--exclude-first-parent-only"),
22982300
(_not, "--not"),
2299-
(_all, "--all"),
2301+
(include_all_refs, "--all"),
23002302
(exclude, "--exclude"),
23012303
(reflog, "--reflog"),
23022304
(alternative_refs, "--alternative-refs"),
@@ -3995,7 +3997,7 @@ def get_url(
39953997
self,
39963998
*,
39973999
push: bool | None = None,
3998-
_all: bool | None = None,
4000+
all_urls: bool | None = None,
39994001
# Pass-through to run()
40004002
log_in_real_time: bool = False,
40014003
check_returncode: bool | None = None,
@@ -4020,15 +4022,15 @@ def get_url(
40204022
>>> GitRemoteCmd(
40214023
... path=example_git_repo.path,
40224024
... remote_name='origin'
4023-
... ).get_url(_all=True)
4025+
... ).get_url(all_urls=True)
40244026
'file:///...'
40254027
"""
40264028
local_flags: list[str] = []
40274029
required_flags: list[str] = [self.remote_name]
40284030

40294031
if push:
40304032
local_flags.append("--push")
4031-
if _all:
4033+
if all_urls:
40324034
local_flags.append("--all")
40334035

40344036
return self.run(
@@ -5097,7 +5099,7 @@ def save(
50975099
keep_index: int | None = None,
50985100
patch: bool | None = None,
50995101
include_untracked: bool | None = None,
5100-
_all: bool | None = None,
5102+
include_ignored: bool | None = None,
51015103
quiet: bool | None = None,
51025104
# Pass-through to run()
51035105
log_in_real_time: bool = False,
@@ -5118,7 +5120,7 @@ def save(
51185120
local_flags: list[str] = []
51195121
stash_flags: list[str] = []
51205122

5121-
if _all is True:
5123+
if include_ignored is True:
51225124
local_flags.append("--all")
51235125
if staged is True:
51245126
local_flags.append("--staged")
@@ -5228,7 +5230,7 @@ def push(
52285230
staged: bool | None = None,
52295231
keep_index: bool | None = None,
52305232
include_untracked: bool | None = None,
5231-
_all: bool | None = None,
5233+
include_ignored: bool | None = None,
52325234
quiet: bool | None = None,
52335235
# Pass-through to run()
52345236
log_in_real_time: bool = False,
@@ -5253,7 +5255,7 @@ def push(
52535255
Keep index intact (-k)
52545256
include_untracked :
52555257
Include untracked files (-u)
5256-
_all :
5258+
include_ignored :
52575259
Include ignored files (-a)
52585260
quiet :
52595261
Suppress output (-q)
@@ -5281,7 +5283,7 @@ def push(
52815283
local_flags.append("-k")
52825284
if include_untracked is True:
52835285
local_flags.append("-u")
5284-
if _all is True:
5286+
if include_ignored is True:
52855287
local_flags.append("-a")
52865288
if quiet is True:
52875289
local_flags.append("-q")
@@ -5921,7 +5923,7 @@ def _ls(
59215923
def ls(
59225924
self,
59235925
*,
5924-
_all: bool = False,
5926+
all_branches: bool = False,
59255927
remotes: bool = False,
59265928
merged: str | None = None,
59275929
no_merged: str | None = None,
@@ -5933,7 +5935,7 @@ def ls(
59335935
59345936
Parameters
59355937
----------
5936-
_all :
5938+
all_branches :
59375939
List all branches (local + remote). Maps to --all.
59385940
remotes :
59395941
List remote branches only. Maps to --remotes.
@@ -5955,7 +5957,7 @@ def ls(
59555957
True
59565958
"""
59575959
local_flags: list[str] = []
5958-
if _all:
5960+
if all_branches:
59595961
local_flags.append("--all")
59605962
if remotes:
59615963
local_flags.append("--remotes")

‎src/libvcs/sync/git.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
From https://github.com/saltstack/salt (Apache License):
66
7-
- :meth:`~libvcs.sync.git.GitSync.remote`
7+
- :meth:`~libvcs.sync.git.GitSync.get_remote`
88
- :meth:`~libvcs.sync.git.GitSync.set_remote`
99
1010
From pip (MIT License):
@@ -424,7 +424,7 @@ def set_remotes(self, overwrite: bool = False) -> None:
424424
remotes = self._remotes
425425
if isinstance(remotes, dict):
426426
for remote_name, git_remote_repo in remotes.items():
427-
existing_remote = self.remote(remote_name)
427+
existing_remote = self.get_remote(remote_name)
428428
if isinstance(git_remote_repo, GitRemote):
429429
if (
430430
not existing_remote
@@ -436,7 +436,7 @@ def set_remotes(self, overwrite: bool = False) -> None:
436436
overwrite=overwrite,
437437
)
438438
# refresh if we're setting it, so push can be checked
439-
existing_remote = self.remote(remote_name)
439+
existing_remote = self.get_remote(remote_name)
440440
if git_remote_repo.push_url and (
441441
not existing_remote
442442
or existing_remote.push_url != git_remote_repo.push_url
@@ -991,7 +991,7 @@ def create_worktree(
991991
self.set_remotes(overwrite=True)
992992
step = "fetch"
993993
self.cmd.fetch(
994-
_all=True,
994+
all_remotes=True,
995995
prune=True,
996996
config={"http.sslVerify": False}
997997
if not self.options.tls_verify
@@ -1123,7 +1123,7 @@ def update_repo(
11231123
self.set_remotes(overwrite=True)
11241124
step = "fetch"
11251125
self.cmd.fetch(
1126-
_all=True,
1126+
all_remotes=True,
11271127
prune=True,
11281128
config={"http.sslVerify": False}
11291129
if not self.options.tls_verify
@@ -1495,7 +1495,7 @@ def get_position(self) -> WorkingCopyPosition:
14951495
)
14961496
return WorkingCopyPosition(revision, revision, "commit", follows=False)
14971497

1498-
def remotes(self) -> GitSyncRemoteDict:
1498+
def get_remotes(self) -> GitSyncRemoteDict:
14991499
"""Return remotes like git remote -v.
15001500
15011501
Parameters
@@ -1513,12 +1513,12 @@ def remotes(self) -> GitSyncRemoteDict:
15131513

15141514
for r in ret:
15151515
# FIXME: Cast to the GitRemote that sync uses, for now
1516-
remote = self.remote(r.remote_name)
1516+
remote = self.get_remote(r.remote_name)
15171517
if remote is not None:
15181518
remotes[r.remote_name] = remote
15191519
return remotes
15201520

1521-
def remote(self, name: str, **kwargs: t.Any) -> GitRemote | None:
1521+
def get_remote(self, name: str, **kwargs: t.Any) -> GitRemote | None:
15221522
"""Get the fetch and push URL for a specified remote name.
15231523
15241524
Parameters
@@ -1597,7 +1597,7 @@ def set_remote(
15971597
else:
15981598
self.cmd.remotes.add(name=name, url=url, check_returncode=True)
15991599

1600-
remote = self.remote(name=name)
1600+
remote = self.get_remote(name=name)
16011601
if remote is None:
16021602
raise GitRemoteSetError(remote_name=name)
16031603
return remote

‎tests/cmd/test_git.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def test_branch_ls_filters(git_repo: GitSync) -> None:
673673
assert any(b.branch_name == "master" for b in branches)
674674

675675
# Test with --all (includes remote-tracking branches)
676-
all_branches = git_repo.cmd.branches.ls(_all=True)
676+
all_branches = git_repo.cmd.branches.ls(all_branches=True)
677677
assert len(all_branches) >= len(branches)
678678

679679
# Test with --merged (branches merged into HEAD)
@@ -2730,21 +2730,21 @@ def test_submodule_entry_absorbgitdirs(
27302730

27312731

27322732
def test_rev_list_all_parameter(git_repo: GitSync) -> None:
2733-
"""Test that _all parameter controls --all flag in rev-list."""
2733+
"""Test that include_all_refs parameter controls --all flag in rev-list."""
27342734
# Create a branch with an extra commit not reachable from master
27352735
git_repo.cmd.run(["checkout", "-b", "other-branch"])
27362736
git_repo.cmd.run(["commit", "--allow-empty", "-m", "other-branch-commit"])
27372737
git_repo.cmd.run(["checkout", "master"])
27382738

2739-
# Without _all: only commits reachable from HEAD (master)
2739+
# Without include_all_refs: only commits reachable from HEAD (master)
27402740
result_no_all = git_repo.cmd.rev_list(commit="HEAD")
27412741
count_no_all = len(result_no_all.strip().split("\n"))
27422742

2743-
# With _all=True: includes commits from all branches
2744-
result_with_all = git_repo.cmd.rev_list(commit="HEAD", _all=True)
2743+
# With include_all_refs=True: includes commits from all branches
2744+
result_with_all = git_repo.cmd.rev_list(commit="HEAD", include_all_refs=True)
27452745
count_with_all = len(result_with_all.strip().split("\n"))
27462746

2747-
# _all=True should return strictly more commits (the other-branch commit)
2747+
# With include_all_refs=True we should get strictly more commits.
27482748
assert count_with_all > count_no_all
27492749

27502750

0 commit comments

Comments
 (0)