Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff046f3

Browse files
committed
!squash more
1 parent56d03ad commitff046f3

File tree

1 file changed

+137
-14
lines changed

1 file changed

+137
-14
lines changed

‎src/libvcs/cmd/git.py‎

Lines changed: 137 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Git:
2121
submodule:"GitSubmoduleCmd"
2222
remote:"GitRemoteCmd"
2323
stash:"GitStashCmd"
24-
branch:"GitBranchCmd"
24+
branch:"GitBranchManager"
2525

2626
def__init__(
2727
self,
@@ -83,7 +83,7 @@ def __init__(
8383
self.submodule=GitSubmoduleCmd(path=self.path,cmd=self)
8484
self.remote=GitRemoteCmd(path=self.path,cmd=self)
8585
self.stash=GitStashCmd(path=self.path,cmd=self)
86-
self.branch=GitBranchCmd(path=self.path,cmd=self)
86+
self.branch=GitBranchManager(path=self.path,cmd=self)
8787

8888
def__repr__(self)->str:
8989
"""Representation of Git repo command object."""
@@ -2974,7 +2974,15 @@ def save(
29742974
classGitBranchCmd:
29752975
"""Run commands directly against a git branch for a git repo."""
29762976

2977-
def__init__(self,*,path:StrPath,cmd:Optional[Git]=None)->None:
2977+
branch_name:str
2978+
2979+
def__init__(
2980+
self,
2981+
*,
2982+
path:StrPath,
2983+
branch_name:str,
2984+
cmd:Optional[Git]=None,
2985+
)->None:
29782986
"""Lite, typed, pythonic wrapper for git-branch(1).
29792987
29802988
Parameters
@@ -2984,13 +2992,128 @@ def __init__(self, *, path: StrPath, cmd: Optional[Git] = None) -> None:
29842992
29852993
Examples
29862994
--------
2987-
>>> GitBranchCmd(path=tmp_path)
2988-
<GitBranchCmd path=...>
2995+
>>> GitBranchCmd(path=tmp_path, branch_name='master')
2996+
<GitBranchCmd path=... branch_name=master>
2997+
2998+
>>> GitBranchCmd(path=tmp_path, branch_name="master").run(quiet=True)
2999+
'fatal: not a git repository (or any of the parent directories): .git'
3000+
3001+
>>> GitBranchCmd(
3002+
... path=git_local_clone.path, branch_name="master").run(quiet=True)
3003+
'* master'
3004+
"""
3005+
#: Directory to check out
3006+
self.path:pathlib.Path
3007+
ifisinstance(path,pathlib.Path):
3008+
self.path=path
3009+
else:
3010+
self.path=pathlib.Path(path)
3011+
3012+
self.cmd=cmdifisinstance(cmd,Git)elseGit(path=self.path)
3013+
3014+
self.branch_name=branch_name
3015+
3016+
def__repr__(self)->str:
3017+
"""Representation of git branch command object."""
3018+
returnf"<GitBranchCmd path={self.path} branch_name={self.branch_name}>"
3019+
3020+
defrun(
3021+
self,
3022+
command:Optional[GitBranchCommandLiteral]=None,
3023+
local_flags:Optional[list[str]]=None,
3024+
*,
3025+
quiet:Optional[bool]=None,
3026+
cached:Optional[bool]=None,# Only when no command entered and status
3027+
# Pass-through to run()
3028+
log_in_real_time:bool=False,
3029+
check_returncode:Optional[bool]=None,
3030+
**kwargs:Any,
3031+
)->str:
3032+
"""Run a command against a git repository's branch.
3033+
3034+
Wraps `git branch <https://git-scm.com/docs/git-branch>`_.
3035+
3036+
Examples
3037+
--------
3038+
>>> GitBranchCmd(path=git_local_clone.path, branch_name='master').run()
3039+
'* master'
3040+
"""
3041+
local_flags=local_flagsifisinstance(local_flags,list)else []
3042+
ifcommandisnotNone:
3043+
local_flags.insert(0,command)
3044+
3045+
ifquietisTrue:
3046+
local_flags.append("--quiet")
3047+
ifcachedisTrue:
3048+
local_flags.append("--cached")
3049+
3050+
returnself.cmd.run(
3051+
["branch",*local_flags],
3052+
check_returncode=check_returncode,
3053+
log_in_real_time=log_in_real_time,
3054+
)
3055+
3056+
defcheckout(self)->str:
3057+
"""Git branch checkout.
3058+
3059+
Examples
3060+
--------
3061+
>>> GitBranchCmd(path=git_local_clone.path, branch_name='master').checkout()
3062+
"Your branch is up to date with 'origin/master'."
3063+
"""
3064+
returnself.cmd.run(
3065+
[
3066+
"checkout",
3067+
*[self.branch_name],
3068+
],
3069+
)
3070+
3071+
defcreate(self)->str:
3072+
"""Create a git branch.
3073+
3074+
Examples
3075+
--------
3076+
>>> GitBranchCmd(path=git_local_clone.path, branch_name='master').create()
3077+
"fatal: a branch named 'master' already exists"
3078+
"""
3079+
returnself.cmd.run(
3080+
[
3081+
"checkout",
3082+
*["-b",self.branch_name],
3083+
],
3084+
# Pass-through to run()
3085+
check_returncode=False,
3086+
)
3087+
3088+
3089+
classGitBranchManager:
3090+
"""Run commands directly related to git branches of a git repo."""
3091+
3092+
branch_name:str
3093+
3094+
def__init__(
3095+
self,
3096+
*,
3097+
path:StrPath,
3098+
cmd:Optional[Git]=None,
3099+
)->None:
3100+
"""Wrap some of git-branch(1), git-checkout(1), manager.
3101+
3102+
Parameters
3103+
----------
3104+
path :
3105+
Operates as PATH in the corresponding git subcommand.
3106+
3107+
Examples
3108+
--------
3109+
>>> GitBranchManager(path=tmp_path)
3110+
<GitBranchManager path=...>
29893111
2990-
>>>GitBranchCmd(path=tmp_path).run(quiet=True)
3112+
>>>GitBranchManager(path=tmp_path).run(quiet=True)
29913113
'fatal: not a git repository (or any of the parent directories): .git'
29923114
2993-
>>> GitBranchCmd(path=git_local_clone.path).run(quiet=True)
3115+
>>> GitBranchManager(
3116+
... path=git_local_clone.path).run(quiet=True)
29943117
'* master'
29953118
"""
29963119
#: Directory to check out
@@ -3003,8 +3126,8 @@ def __init__(self, *, path: StrPath, cmd: Optional[Git] = None) -> None:
30033126
self.cmd=cmdifisinstance(cmd,Git)elseGit(path=self.path)
30043127

30053128
def__repr__(self)->str:
3006-
"""Representation of git branchstorage command object."""
3007-
returnf"<GitBranchCmd path={self.path}>"
3129+
"""Representation of git branchmanager object."""
3130+
returnf"<GitBranchManager path={self.path}>"
30083131

30093132
defrun(
30103133
self,
@@ -3018,13 +3141,13 @@ def run(
30183141
check_returncode:Optional[bool]=None,
30193142
**kwargs:Any,
30203143
)->str:
3021-
"""Run a command against a git repository'sbranch storage.
3144+
"""Run a command against a git repository'sbranches.
30223145
30233146
Wraps `git branch <https://git-scm.com/docs/git-branch>`_.
30243147
30253148
Examples
30263149
--------
3027-
>>>GitBranchCmd(path=git_local_clone.path).run()
3150+
>>>GitBranchManager(path=git_local_clone.path).run()
30283151
'* master'
30293152
"""
30303153
local_flags=local_flagsifisinstance(local_flags,list)else []
@@ -3047,7 +3170,7 @@ def checkout(self, *, branch: str) -> str:
30473170
30483171
Examples
30493172
--------
3050-
>>>GitBranchCmd(path=git_local_clone.path).checkout(branch='master')
3173+
>>>GitBranchManager(path=git_local_clone.path).checkout(branch='master')
30513174
"Your branch is up to date with 'origin/master'."
30523175
"""
30533176
returnself.cmd.run(
@@ -3062,7 +3185,7 @@ def create(self, *, branch: str) -> str:
30623185
30633186
Examples
30643187
--------
3065-
>>>GitBranchCmd(path=git_local_clone.path).create(branch='master')
3188+
>>>GitBranchManager(path=git_local_clone.path).create(branch='master')
30663189
"fatal: a branch named 'master' already exists"
30673190
"""
30683191
returnself.cmd.run(
@@ -3079,7 +3202,7 @@ def ls(self) -> str:
30793202
30803203
Examples
30813204
--------
3082-
>>>GitBranchCmd(path=git_local_clone.path).ls()
3205+
>>>GitBranchManager(path=git_local_clone.path).ls()
30833206
'* master'
30843207
"""
30853208
returnself.run(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp