Skip to content

Commit b752107

Browse files
committed
cmd/git(feat[GitRemoteCmd]): add set_branches, set_head, update methods
why: Complete GitRemoteCmd per-entity operations what: - Add set_branches() method with add flag (--add) - Add set_head() method with auto (-a) and delete (-d) flags - Add update() method with prune flag (-p)
1 parent 9fa395f commit b752107

1 file changed

Lines changed: 146 additions & 0 deletions

File tree

src/libvcs/cmd/git.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,6 +2900,152 @@ def set_url(
29002900
log_in_real_time=log_in_real_time,
29012901
)
29022902

2903+
def set_branches(
2904+
self,
2905+
*branches: str,
2906+
add: bool = False,
2907+
# Pass-through to run()
2908+
log_in_real_time: bool = False,
2909+
check_returncode: bool | None = None,
2910+
) -> str:
2911+
"""Git remote set-branches.
2912+
2913+
Configure remote tracking branches for the remote.
2914+
2915+
Parameters
2916+
----------
2917+
*branches :
2918+
Branch names to track.
2919+
add :
2920+
Add to existing tracked branches instead of replacing.
2921+
2922+
Examples
2923+
--------
2924+
>>> GitRemoteCmd(
2925+
... path=example_git_repo.path,
2926+
... remote_name='origin'
2927+
... ).set_branches('master')
2928+
''
2929+
2930+
>>> GitRemoteCmd(
2931+
... path=example_git_repo.path,
2932+
... remote_name='origin'
2933+
... ).set_branches('master', 'develop', add=True)
2934+
''
2935+
"""
2936+
local_flags: list[str] = []
2937+
2938+
if add:
2939+
local_flags.append("--add")
2940+
2941+
local_flags.append(self.remote_name)
2942+
local_flags.extend(branches)
2943+
2944+
return self.run(
2945+
"set-branches",
2946+
local_flags=local_flags,
2947+
check_returncode=check_returncode,
2948+
log_in_real_time=log_in_real_time,
2949+
)
2950+
2951+
def set_head(
2952+
self,
2953+
branch: str | None = None,
2954+
*,
2955+
auto: bool = False,
2956+
delete: bool = False,
2957+
# Pass-through to run()
2958+
log_in_real_time: bool = False,
2959+
check_returncode: bool | None = None,
2960+
) -> str:
2961+
"""Git remote set-head.
2962+
2963+
Set or delete the default branch (HEAD) for the remote.
2964+
2965+
Parameters
2966+
----------
2967+
branch :
2968+
Branch name to set as HEAD. Required unless auto or delete is True.
2969+
auto :
2970+
Query the remote to determine HEAD automatically.
2971+
delete :
2972+
Delete the remote HEAD reference.
2973+
2974+
Examples
2975+
--------
2976+
>>> GitRemoteCmd(
2977+
... path=example_git_repo.path,
2978+
... remote_name='origin'
2979+
... ).set_head(auto=True)
2980+
'origin/HEAD set to master'
2981+
2982+
>>> GitRemoteCmd(
2983+
... path=example_git_repo.path,
2984+
... remote_name='origin'
2985+
... ).set_head('master')
2986+
''
2987+
"""
2988+
local_flags: list[str] = [self.remote_name]
2989+
2990+
if auto:
2991+
local_flags.append("-a")
2992+
elif delete:
2993+
local_flags.append("-d")
2994+
elif branch is not None:
2995+
local_flags.append(branch)
2996+
2997+
return self.run(
2998+
"set-head",
2999+
local_flags=local_flags,
3000+
check_returncode=check_returncode,
3001+
log_in_real_time=log_in_real_time,
3002+
)
3003+
3004+
def update(
3005+
self,
3006+
*,
3007+
prune: bool = False,
3008+
# Pass-through to run()
3009+
log_in_real_time: bool = False,
3010+
check_returncode: bool | None = None,
3011+
) -> str:
3012+
"""Git remote update.
3013+
3014+
Fetch updates for the remote.
3015+
3016+
Parameters
3017+
----------
3018+
prune :
3019+
Prune remote-tracking branches no longer on remote.
3020+
3021+
Examples
3022+
--------
3023+
>>> GitRemoteCmd(
3024+
... path=example_git_repo.path,
3025+
... remote_name='origin'
3026+
... ).update()
3027+
'Fetching origin...'
3028+
3029+
>>> GitRemoteCmd(
3030+
... path=example_git_repo.path,
3031+
... remote_name='origin'
3032+
... ).update(prune=True)
3033+
'Fetching origin...'
3034+
"""
3035+
local_flags: list[str] = []
3036+
3037+
if prune:
3038+
local_flags.append("-p")
3039+
3040+
local_flags.append(self.remote_name)
3041+
3042+
return self.run(
3043+
"update",
3044+
local_flags=local_flags,
3045+
check_returncode=check_returncode,
3046+
log_in_real_time=log_in_real_time,
3047+
)
3048+
29033049

29043050
GitRemoteManagerLiteral = t.Literal[
29053051
"--verbose",

0 commit comments

Comments
 (0)