o
    Yh                     @  sr   d dl mZ d dlZd dlZd dlmZmZ d dlmZ er*d dl	m
Z
mZmZmZ dZdZdZG d	d
 d
ZdS )    )annotationsN)TYPE_CHECKINGcast)util)CommitRemoteRemoteReferenceRepoz/^https://(www\.)?github.com/(.+)/(.+)(?:.git)?$z#^git@github.com:(.+)/(.+)(?:.git)?$)      r   c                   @  s   e Zd ZU ded< d$ddZd%d	d
Zd&ddZed'ddZed(ddZ	ed&ddZ
ed(ddZed)ddZd*ddZd&ddZd+d!d"Zd#S ),GitRepozRepo | NonerepopathstrreturnNonec                 C  s   d | _ z4dd l}|j|dd| _| jjj| _ | j d ur2| j tkr5| jjd}tj	||| _
W d S W d S W d S  tyD   d | _Y d S w )Nr   T)search_parent_directoriesz--show-toplevel)git_versiongitr	   r   version_infoMIN_GIT_VERSION	rev_parseosr   relpathmodule	Exception)selfr   r   git_root r   S/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/git_util.py__init__'   s   zGitRepo.__init__c                 C  s
   t | S N)r   repr_r   r   r   r   __repr__=   s   
zGitRepo.__repr__boolc                 C  s   | j duo| jduo| jtkS )zDTrue if there's a git repo here, and git.version >= MIN_GIT_VERSION.N)r   r   r   r#   r   r   r   is_valid@   s
   
zGitRepo.is_validRemoteReference | Nonec                 C  s,   | j d u s	|  sd S | jrd S | j j S r!   )r   r&   is_head_detachedactive_branchtracking_branchr#   r   r   r   r*   H   s
   zGitRepo.tracking_branchlist[str] | Nonec                 C  s   | j d u s	|  sd S | j jS r!   )r   r&   untracked_filesr#   r   r   r   r,   R   s   zGitRepo.untracked_filesc                 C  s    | j d u s	|  sdS | j jjS )NF)r   r&   headis_detachedr#   r   r   r   r(   Y   s   
zGitRepo.is_head_detachedc                 C  s.   | j d u s	|  sd S dd | j jd D S )Nc                 S  s   g | ]}t d |jqS )r   )r   a_path).0itemr   r   r   
<listcomp>e   s    z-GitRepo.uncommitted_files.<locals>.<listcomp>)r   r&   indexdiffr#   r   r   r   uncommitted_files`   s   zGitRepo.uncommitted_fileslist[Commit] | Nonec                 C  sx   | j d u s	|  sd S z%|  }|d u rW d S |\}}|j d| }t| j | d| W S  ty;   g  Y S w )N/z..)r   r&   get_tracking_branch_remotenamelistiter_commitsr   )r   tracking_branch_inforemotebranch_nameremote_branchr   r   r   ahead_commitsg   s   zGitRepo.ahead_commitstuple[Remote, str] | Nonec                 C  sR   | j d u s	|  sd S | j}|d u rd S |jd^}}d|}| j ||fS )Nr7   )r   r&   r*   r9   splitjoinr=   )r   r*   remote_namebranchr>   r   r   r   r8   x   s   
z"GitRepo.get_tracking_branch_remotec                 C  s^   |   sdS |  }|d u rdS |\}}|jD ]}tt|d us)tt|d ur, dS qdS )NFT)r&   r8   urlsrematchGITHUB_HTTP_URLGITHUB_SSH_URL)r   remote_infor=   _branchurlr   r   r   is_github_repo   s   
zGitRepo.is_github_repotuple[str, str, str] | Nonec                 C  s   |   sd S |  }|d u rd S |\}}d }|jD ]4}tt|}tt|}|d ur:|d d|d } n|d urM|d d|d } nq|d u rTd S ||| jfS )Nr
   r7         )	r&   r8   rF   rG   rH   rI   rJ   groupr   )r   rK   r=   rE   r   rM   https_matchesssh_matchesr   r   r   get_repo_info   s(   
zGitRepo.get_repo_infoN)r   r   r   r   )r   r   )r   r%   )r   r'   )r   r+   )r   r6   )r   rA   )r   rO   )__name__
__module____qualname____annotations__r    r$   r&   propertyr*   r,   r(   r5   r@   r8   rN   rU   r   r   r   r   r   $   s$   
 


	

r   )
__future__r   r   rG   typingr   r   	streamlitr   r   r   r   r   r	   rI   rJ   r   r   r   r   r   r   <module>   s   