o
    ,&]it                     @  s   U d dl mZ d dlZd dlZd dlmZmZmZ d dlm	Z	 d dl
mZ er3d dlmZmZmZmZ eeZded< ed	Zded
< dZded< dddZG dd dZdS )    )annotationsN)TYPE_CHECKINGFinalcast)util)
get_logger)CommitRemoteRemoteReferenceRepor   _LOGGERz5github\.com(?::\d+)?[/:]([^/]+)/([^/]+?)(?:\.git)?/?$_GITHUB_URL_PATTERN)      r   _MIN_GIT_VERSIONurlstrreturn
str | Nonec                 C  s4   t |  }|du rdS |d d|d S )a  Extract the ``owner/repo`` from a GitHub remote URL.

    This supports HTTPS and SSH URL forms including optional user info, port,
    trailing slash, and ``.git`` suffix. Validation of the scheme is not
    performed; we only extract if the URL contains ``github.com`` and ends with
    a path of the shape ``owner/repo``.

    Parameters
    ----------
    url
        The remote URL string.

    Returns
    -------
    str | None
        The extracted ``owner/repo`` if found; otherwise ``None``.
    N   /r   )r   searchstripgroup)r   match r   P/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/git_util.py_extract_github_repo_from_url)   s   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!S )*GitRepozRepo | Nonerepopathr   r   Nonec                 C  s   d | _ d| _z6dd l}|j|dd| _| jjj| _ | j d ur7| j tkr:| jjd}tt	j
||| _W d S W d S W d S  tyQ   tjd|dd d | _Y d S w )N r   T)search_parent_directoriesz--show-toplevelzDid not find a git repo at %s. This is expected if this isn't a git repo, but could also fail for other reasons: 1) git binary or GitPython not installed 2) No .git folder 3) Corrupted .git folder 4) Path is invalid.exc_info)git_versionmodulegitr   r   version_infor   	rev_parser   osr    relpath	Exceptionr   debug)selfr    r(   git_rootr   r   r   __init__D   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 )zETrue if there's a git repo here, and git.version >= _MIN_GIT_VERSION.N)r   r&   r   r4   r   r   r   is_validc   s
   
zGitRepo.is_validRemoteReference | Nonec                 C  s,   | j d u s	|  sd S | jrd S | j j S r2   )r   r7   is_head_detachedactive_branchtracking_branchr4   r   r   r   r;   k   s
   zGitRepo.tracking_branchlist[str] | Nonec                 C  s   | j d u s	|  sd S | j jS r2   )r   r7   untracked_filesr4   r   r   r   r=   u   s   zGitRepo.untracked_filesc                 C  s    | j d u s	|  sdS | j jjS )NF)r   r7   headis_detachedr4   r   r   r   r9   |   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>   s    z-GitRepo.uncommitted_files.<locals>.<listcomp>)r   r7   indexdiffr4   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 )Nr   z..)r   r7   get_tracking_branch_remotenamelistiter_commitsr-   )r/   tracking_branch_inforemotebranch_nameremote_branchr   r   r   ahead_commits   s   zGitRepo.ahead_commitstuple[Remote, str] | Nonec                 C  sz   | j d u s	|  sd S | j}|d u rd S |jd^}}d|}z	| j ||fW S  ty<   tj	d|dd Y d S w )Nr   zFailed to resolve remote %sTr$   )
r   r7   r;   rI   splitjoinrM   r-   r   r.   )r/   r;   remote_namebranchrN   r   r   r   rH      s   
z"GitRepo.get_tracking_branch_remotetuple[str, str, str] | Nonec                 C  s   |   std| j d S |  }|d u rtd d S |\}}t|j}d }|D ]}t|}|d ur5 nq)|d u rBtd| d S ||| jfS )Nz/No valid git information found. Git version: %sz1No tracking remote branch found for the git repo.zCUnable to determine repo name from configured remote URLs. URLs: %s)	r7   r   r.   r&   rH   rJ   urlsr   r'   )r/   remote_inforM   rU   remote_urlsr   r   r   r   r   get_repo_info   s0   

zGitRepo.get_repo_infoN)r    r   r   r!   )r   r   )r   r6   )r   r8   )r   r<   )r   rG   )r   rQ   )r   rV   )__name__
__module____qualname____annotations__r1   r5   r7   propertyr;   r=   r9   rF   rP   rH   rZ   r   r   r   r   r   A   s"   
 


	
r   )r   r   r   r   )
__future__r   r+   retypingr   r   r   	streamlitr   streamlit.loggerr   r(   r   r	   r
   r   r[   r   r^   compiler   r   r   r   r   r   r   r   <module>   s   
