
    5pj+                        S r SSKJr  SSKJr  SSKJrJr  SSKJ	r	J
r
  SSKJr  SSKJr  \" S	5      rS
r " S S5      rg)zLocal Git repository representation.

Wraps :class:`~._git.GitCommand` to provide a higher-level OOP interface
for cloning, pushing, and managing a local checkout tied to a ModelScope
Hub remote.
    )annotations)Path   )
GitCommandGitError)DEFAULT_ENDPOINTRepoType)
ensure_dir)
get_logger
repositoryz {endpoint}/{type}s/{repo_id}.gitc                      \ rS rSrSrSS\R                  S\4             SS jjr\	SS j5       r
\	SS j5       r\	SS j5       r\	SS j5       rSSS	 jjrSSS
 jjrSSS jjrSSS jjrSS jrSS jrSrg)
Repository   zLocal Git repository representation.

Provides lifecycle management for a local checkout linked to a
ModelScope Hub remote repository.
Nc                8   [        U5      R                  5       U l        XPl        UR	                  S5      U l        X@l        X0l        U(       a  X l        gU(       a8  UR                  S5      (       d  U S3OUnU R
                   SU SU S3U l        gSU l        g)a  
Parameters
----------
repo_dir:
    Local directory for the repository checkout.
repo_url:
    Explicit Git remote URL. If not provided, computed from
    repo_id + repo_type + endpoint.
repo_id:
    Repository identifier (``owner/name``). Used to compute
    repo_url when it's not given directly.
repo_type:
    Repository type (model, dataset, etc.).
token:
    OAuth2 token for authenticated operations.
endpoint:
    Hub endpoint for URL construction.
/s.git N)
r   resolve	_repo_dir_tokenrstrip	_endpoint
_repo_type_repo_id	_repo_urlendswith)selfrepo_dirrepo_urlrepo_id	repo_typetokenendpointsegments           V/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope_hub/_repository.py__init__Repository.__init__   s    6 h//1!-#%N-6-?-?-D-D1o)G $/q	7)4HDNDN    c                    U R                   $ )z0Absolute path to the local repository directory.)r   r   s    r&   r   Repository.repo_dirJ        ~~r)   c                    U R                   $ )z.Remote Git URL (without embedded credentials).)r   r+   s    r&   git_urlRepository.git_urlO   r-   r)   c                X    [         R                  " U R                  U R                  5      $ )z1Remote Git URL with token injected for push/pull.)r   _inject_tokenr   r   r+   s    r&   authenticated_urlRepository.authenticated_urlT   s     ''DDr)   c                <    U R                   S-  R                  5       $ )z@Whether the local repo directory already contains a .git folder.r   )r   is_dirr+   s    r&   existsRepository.existsY   s     '//11r)   c                   U R                   (       a!  [        R                  SU R                  5        g[	        U R                  R
                  5        [        R                  S[        R                  " U R                  5      U R                  5        [        R                  " U R                  U R                  UU R                  US9  [        R                  " 5       (       a!  [        R                  " U R                  5        gg)zClone the remote repository into :attr:`repo_dir`.

Parameters
----------
revision:
    Branch or tag to checkout after clone.
depth:
    Shallow clone depth (None for full history).
zRepository already cloned at %sNu   Cloning %s → %s)url
target_dirbranchr#   depth)r7   loggerinfor   r
   parentr   strip_token_from_urlr   cloner   is_lfs_availablelfs_install)r   revisionr=   s      r&   rB   Repository.clonea   s     ;;KK94>>J4>>(()')H)H)XZ^ZhZhi~~++	
 &&((""4>>2 )r)   c                    U R                  5         U R                  5         [        R                  " U R                  US9  g)z$Pull latest changes from the remote.r<   N)_ensure_exists_configure_authr   pullr   )r   r<   s     r&   rK   Repository.pull~   s,    v6r)   c                   U R                  5         U R                  5         [        R                  " U R                  5         [        R
                  " U R                  U5        [        R                  " U R                  US9  [        R                  S[        R                  " U R                  5      5        g! [         a=  nS[        U5      R                  5       ;   a  [        R                  S5         SnAge SnAff = f)zStage all changes, commit, and push.

Parameters
----------
commit_message:
    Message for the commit.
branch:
    Branch to push to (default: current branch).
nothing to commitNothing to commitNrH   zPushed to %s)rI   rJ   r   addr   commitr   strlowerr>   r?   pushrA   r   )r   commit_messager<   excs       r&   rT   Repository.push   s     	 	t~~&	dnnn= 	v6NJ$C$CDNN$ST  	"c#hnn&66/0		s   !B7 7
C>2C98C99C>c                   U R                  5         U(       a"  [        R                  " U R                  /UQ76   O [        R                  " U R                  5         [        R                  " U R                  U5        g! [
         a=  nS[        U5      R                  5       ;   a  [        R                  S5         SnAge SnAff = f)z9Stage specific paths (or all) and commit without pushing.rN   rO   N)
rI   r   rP   r   rQ   r   rR   rS   r>   r?   )r   messagepathsrV   s       r&   add_and_commitRepository.add_and_commit   s    NN4>>2E2NN4>>*	dnng6 	"c#hnn&66/0		s   !A= =
C2B?>B??Cc                X    U R                   (       d  [        SU R                   S35      eg)z&Raise if the local repo doesn't exist.zRepository not found at z. Call clone() first.N)r7   r   r   r+   s    r&   rI   Repository._ensure_exists   s)    {{5dnn5EEZ[\\ r)   c                   U R                   (       d  g[        R                  " U R                  U R                   5      n [        R                  " U R
                  U5        g! [         a    [        R                  S5         gf = f)z7Inject token into the remote URL for authenticated ops.Nz$Could not update remote URL for auth)	r   r   r2   r   set_remote_urlr   r   r>   debug)r   auth_urls     r&   rJ   Repository._configure_auth   s^    {{++DNNDKKH	A%%dnnh? 	ALL?@	As   !A! !BB)r   r   r   r   r   r   )r   z
Path | strr    
str | Noner!   rd   r"   rR   r#   rd   r$   rR   returnNone)re   r   )re   rR   )re   bool)masterN)rE   rR   r=   z
int | Nonere   rf   )N)r<   rd   re   rf   )rU   rR   r<   rd   re   rf   )rY   rR   rZ   zlist[str] | Nonere   rf   )re   rf   )__name__
__module____qualname____firstlineno____doc__r	   MODELr   r'   propertyr   r/   r3   r7   rB   rK   rT   r[   rI   rJ   __static_attributes__ r)   r&   r   r      s      $"! (' '  '  	' 
 '  '  '  
' X     E E 2 23:7U:&]
Ar)   r   N)rm   
__future__r   pathlibr   _gitr   r   	constantsr   r	   utils.file_utilsr
   utils.loggerr   r>   _GIT_URL_TEMPLATEr   rq   r)   r&   <module>ry      s>    #  & 1 ( $	L	! 7 jA jAr)   