o
    沪g                     @  sR   d dl mZ d dlZd dlZd dlmZ d dlmZ dZdZ	dZ
G dd	 d	ZdS )
    )annotationsN)Any)utilz/^https://(www\.)?github.com/(.+)/(.+)(?:.git)?$z#^git@github.com:(.+)/(.+)(?:.git)?$)      r   c                   @  s~   e Zd Zdd ZdddZddd	Zed
d Zedd Zedd Z	edd Z
edd Zdd ZdddZdd ZdS )GitRepoc                 C  s~   d | _ z.dd l}|}|j|dd| _| jjj| _ | j tkr/| jjd}tj	||| _
W d S W d S  ty>   d | _Y d S w )Nr   T)search_parent_directoriesz--show-toplevel)git_versiongitReporepoversion_infoMIN_GIT_VERSION	rev_parseospathrelpathmodule	Exception)selfr   r
   git_packagegit_root r   N/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/streamlit/git_util.py__init__"   s   
zGitRepo.__init__returnstrc                 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_validc                 C  s"   |   sd S | jrd S | jj S r   )r"   is_head_detachedr   active_branchtracking_branchr   r   r   r   r%   G   s
   zGitRepo.tracking_branchc                 C  s   |   sd S | jjS r   )r"   r   untracked_filesr   r   r   r   r&   Q   s   zGitRepo.untracked_filesc                 C  s   |   sdS | jjjS )NF)r"   r   headis_detachedr   r   r   r   r#   X   s   
zGitRepo.is_head_detachedc                 C  s$   |   sd S dd | jjd D S )Nc                 S  s   g | ]}|j qS r   )a_path).0itemr   r   r   
<listcomp>d   s    z-GitRepo.uncommitted_files.<locals>.<listcomp>)r"   r   indexdiffr   r   r   r   uncommitted_files_   s   zGitRepo.uncommitted_filesc                 C  s\   |   sd S z|  \}}|j d| }t| j| d| W S  ty-   g  Y S w )N/z..)r"   get_tracking_branch_remotenamelistr   iter_commitsr   )r   remotebranch_nameremote_branchr   r   r   ahead_commitsf   s   zGitRepo.ahead_commitsc                 C  sH   |   sd S | j}|d u rd S |jd^}}d|}| j||fS )Nr0   )r"   r%   r2   splitjoinr   r5   )r   r%   remote_namebranchr6   r   r   r   r1   s   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"   r1   urlsrematchGITHUB_HTTP_URLGITHUB_SSH_URL)r   remote_infor5   _branchurlr   r   r   is_github_repo   s   
zGitRepo.is_github_repoc                 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   r0         )	r"   r1   r=   r>   r?   r@   rA   groupr   )r   rB   r5   r<   r   rD   https_matchesssh_matchesr   r   r   get_repo_info   s(   
zGitRepo.get_repo_infoN)r   r   )r   r!   )__name__
__module____qualname__r   r    r"   propertyr%   r&   r#   r/   r8   r1   rE   rK   r   r   r   r   r   !   s"    


	




r   )
__future__r   r   r>   typingr   	streamlitr   r@   rA   r   r   r   r   r   r   <module>   s   