o
    -wi                     @   s   d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	 ddl
mZ dZdZd	Zed
ZG dd deZdedeee ee ef fddZeG dd dZdS )zVSupport for parsing GitHub URLs (which might be user provided) into constituent parts.    N)	dataclass)IntEnum)OptionalTupleUnion)LaunchErrorzhttps://zgit@z.gitz[0-9a-f]{40}c                   @   s   e Zd ZdZdZdS )ReferenceType      N)__name__
__module____qualname__BRANCHCOMMIT r   r   [/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/sdk/launch/git_reference.pyr      s    r   netlocreturnc                 C   sf   |  dd}t|dkrdd|d fS |\}}| dd}t|dkr*|d d|fS |d |d |fS )zParse netloc into username, password, and host.

    github.com => None, None, "@github.com"
    username@github.com => "username", None, "github.com"
    username:password@github.com => "username", "password", "github.com"
    @r	   Nr   :)splitlen)r   partsauthhostr   r   r   _parse_netloc   s   r   c                   @   sP   e Zd Zddedee ddfddZedee fddZd	eddfd
dZdS )GitReferenceNremoterefr   c                 C   s   || _ || _dS )zInitialize a reference from a remote and ref.

        Arguments:
            remote: A remote URL or URI.
            ref: A branch, tag, or commit hash.
        N)urir   )selfr   r   r   r   r   __init__*   s   
zGitReference.__init__c                 C   s   | j S N)r   )r    r   r   r   url4   s   zGitReference.urldst_dirc           
   
   C   s`  ddl }|j|}|j| _|d| jpd}z|  W n |jj	y6 } zt
d| j d| d}~ww | jr[| j|jv rG|j| j }n| j}|| j|}|  |jj| _nLd}|jD ]$}t|drhq`|j}	|	drv|	d	d }	|	d
kr~d
} n|	dkrd}q`|st
d| j || _|| _|||j| }|  |jj| _|jddd dS )zHFetch the repo into dst_dir and refine githubref based on what we learn.r   Norigin z+Unable to fetch from git remote repository z:
tagzorigin/   mainmasterz6Unable to determine branch or commit to checkout from T)init	recursive)gitRepor+   working_dirpathcreate_remoter   fetchexcGitCommandErrorr   r#   r   refscreate_headcheckoutcommithexshacommit_hash
referenceshasattrname
startswithdefault_branchsubmodule_update)
r    r$   r-   repor%   er   headr?   refnamer   r   r   r2   8   sT   




zGitReference.fetchr"   )	r   r   r   strr   r!   propertyr#   r2   r   r   r   r   r   (   s
    
r   )__doc__redataclassesr   enumr   typingr   r   r   wandb.sdk.launch.errorsr   PREFIX_HTTPS
PREFIX_SSH
SUFFIX_GITcompileGIT_COMMIT_REGEXr   rE   r   r   r   r   r   r   <module>   s    
$