
    /_it                        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rd dlmZmZmZmZ  ee      Zded<    ej(                  d	      Zded
<   dZded<   ddZ G d d      Zy)    )annotationsN)TYPE_CHECKINGFinalcast)util)
get_logger)CommitRemoteRemoteReferenceRepor   _LOGGERz5github\.com(?::\d+)?[/:]([^/]+)/([^/]+?)(?:\.git)?/?$_GITHUB_URL_PATTERN)      r   _MIN_GIT_VERSIONc                    t         j                  | j                               }|y|j                  d       d|j                  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)urlmatchs     Q/var/www/html/land_sniper/venv/lib/python3.12/site-packages/streamlit/git_util.py_extract_github_repo_from_urlr   )   sE    $  &&syy{3E}kk!nQu{{1~.//    c                      e Zd ZU ded<   ddZddZ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Zy)GitRepozRepo | Nonerepoc                   d | _         d| _        	 dd l}|j                  |d      | _        | j                  j                  j
                  | _         | j                   h| j                   t        k\  rT| j                  j                  j                  d      }t        t        j                  j                  ||            | _        y y y # t        $ r" t        j                  d|d       d | _        Y y w xY 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_parsestrospathrelpath	Exceptionr   debug)selfr,   r'   git_roots       r   __init__zGitRepo.__init__D   s     48	FDI#yy}}99D+0@0@DT0T99==223DE!"''//$"AB 1U+  	MM&   	 DI	s   B3C (C10C1c                ,    t        j                  |       S N)r   repr_r0   s    r   __repr__zGitRepo.__repr__`   s    zz$r   c                h    | j                   duxr# | j                  duxr | j                  t        k\  S )zETrue if there's a git repo here, and git.version >= _MIN_GIT_VERSION.N)r   r%   r   r6   s    r   is_validzGitRepo.is_validc   s<     IIT! 5  ,5  $44	
r   c                    | j                   | j                         sy | j                  ry | j                   j                  j	                         S r4   )r   r9   is_head_detachedactive_branchtracking_branchr6   s    r   r=   zGitRepo.tracking_branchk   s<    99DMMO  yy&&6688r   c                h    | j                   | j                         sy | j                   j                  S r4   )r   r9   untracked_filesr6   s    r   r?   zGitRepo.untracked_filesu   s'    99DMMOyy(((r   c                |    | j                   | j                         sy| j                   j                  j                  S )NF)r   r9   headis_detachedr6   s    r   r;   zGitRepo.is_head_detached|   s+    99DMMOyy~~)))r   c                    | j                   | j                         sy | j                   j                  j                  d       D cg c]  }t	        d|j
                         c}S c c}w )Nr*   )r   r9   indexdiffr   a_path)r0   items     r   uncommitted_fileszGitRepo.uncommitted_files   sI    99DMMO59YY__5I5I$5OPTUDKK(PPPs   A%c                   | j                   | j                         sy 	 | j                         }|y |\  }}|j                   d| }t	        | j                   j                  | d|             S # t        $ r g cY S w xY w)Nr   z..)r   r9   get_tracking_branch_remotenamelistiter_commitsr.   )r0   tracking_branch_inforemotebranch_nameremote_branchs        r   ahead_commitszGitRepo.ahead_commits   s    99DMMO
	#'#B#B#D #+"6FK%{{m1[M:M		..-;-/PQRR 	I	s   A1 >A1 1A?>A?c                @   | j                   | j                         sy | j                  }|y |j                  j	                  d      ^}}dj                  |      }	 | j                   j                  |      |fS # t        $ r t        j                  d|d       Y y w xY w)Nr   zFailed to resolve remote %sTr#   )
r   r9   r=   rK   splitjoinrO   r.   r   r/   )r0   r=   remote_namebranchrP   s        r   rJ   z"GitRepo.get_tracking_branch_remote   s    99DMMO..".3399#>fhhv&	99##K0+== 	MM7tMT	s   A9 9!BBc                h   | j                         s!t        j                  d| j                         y | j	                         }|t        j                  d       y |\  }}t        |j                        }d }|D ]  }t        |      }| n |t        j                  d|       y ||| 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)	r9   r   r/   r%   rJ   rL   urlsr   r&   )r0   remote_inforO   rW   remote_urlsr   r   s          r   get_repo_infozGitRepo.get_repo_info   s    }}MMA4CSCS 557MMMN$6;;' 	C05D	
 <MMU VT[[((r   N)r,   r*   returnNone)r]   r*   )r]   bool)r]   zRemoteReference | None)r]   zlist[str] | None)r]   zlist[Commit] | None)r]   ztuple[Remote, str] | None)r]   ztuple[str, str, str] | None)__name__
__module____qualname____annotations__r2   r7   r9   propertyr=   r?   r;   rH   rR   rJ   r\    r   r   r   r   A   s    
8 
 9 9 ) ) * * Q Q   $)r   r   )r   r*   r]   z
str | None)
__future__r   r+   retypingr   r   r   	streamlitr   streamlit.loggerr   r'   r	   r
   r   r   r`   r   rc   compiler   r   r   r   re   r   r   <module>rl      so    # 	 	 - -  '99H% % (RZZ< U  $ % #00G) G)r   