Skip to content

Commit cc70cd8

Browse files
committed
cmd/git(feat[GitBranchManager.ls]): add verbose parameter
why: Complete GitBranchManager.ls() filter options to match GitTagManager.ls() what: - Add verbose: bool parameter to ls() method - Add helper function to extract branch name from verbose output - Verbose output format is "name sha1 message" - parse correctly - Add test for verbose parameter in test_branch_ls_filters
1 parent a02b871 commit cc70cd8

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/libvcs/cmd/git.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5726,6 +5726,7 @@ def ls(
57265726
no_merged: str | None = None,
57275727
contains: str | None = None,
57285728
sort: str | None = None,
5729+
verbose: bool = False,
57295730
) -> QueryList[GitBranchCmd]:
57305731
"""List branches.
57315732
@@ -5743,6 +5744,8 @@ def ls(
57435744
Only list branches containing specified commit.
57445745
sort :
57455746
Sort key (e.g., '-committerdate', 'refname').
5747+
verbose :
5748+
Show sha1 and commit subject line for each head. Maps to --verbose.
57465749
57475750
Examples
57485751
--------
@@ -5763,11 +5766,22 @@ def ls(
57635766
local_flags.extend(["--contains", contains])
57645767
if sort is not None:
57655768
local_flags.extend(["--sort", sort])
5769+
if verbose:
5770+
local_flags.append("--verbose")
5771+
5772+
def extract_branch_name(line: str) -> str:
5773+
"""Extract branch name from output line (handles verbose output)."""
5774+
# Strip leading "* " or " " marker
5775+
name = line.lstrip("* ")
5776+
# With --verbose, format is: "name sha1 message" - take first token
5777+
if verbose:
5778+
name = name.split()[0] if name.split() else name
5779+
return name
57665780

57675781
return QueryList(
57685782
[
5769-
GitBranchCmd(path=self.path, branch_name=branch_name.lstrip("* "))
5770-
for branch_name in self._ls(local_flags=local_flags or None)
5783+
GitBranchCmd(path=self.path, branch_name=extract_branch_name(line))
5784+
for line in self._ls(local_flags=local_flags or None)
57715785
],
57725786
)
57735787

tests/cmd/test_git.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,11 @@ def test_branch_ls_filters(git_repo: GitSync) -> None:
526526
sorted_branches = git_repo.cmd.branches.ls(sort="refname")
527527
assert isinstance(sorted_branches, list)
528528

529+
# Test with --verbose (should still extract branch names correctly)
530+
verbose_branches = git_repo.cmd.branches.ls(verbose=True)
531+
assert isinstance(verbose_branches, list)
532+
assert any(b.branch_name == "master" for b in verbose_branches)
533+
529534

530535
# =============================================================================
531536
# GitRemoteCmd Tests

0 commit comments

Comments
 (0)