
    e>              	           d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZ ddlmZ  ej&                  e      Zd	d
gZd Zd Z	 	 	 ddede	e   dddefdZy)z:Helper functions for working with version control systems.    N)Path)which)Optional)RepositoryCloneFailedRepositoryNotFoundUnknownRepoTypeVCSNotInstalled)prompt_and_delete)make_sure_path_existszerror: pathspeczunknown revisionc                     | j                  d      }t        |      dk(  r|d   }|dv r||d   fS t        d| v rd| fS d| v rd| fS t        )	a  Determine if `repo_url` should be treated as a URL to a git or hg repo.

    Repos can be identified by prepending "hg+" or "git+" to the repo URL.

    :param repo_url: Repo URL of unknown type.
    :returns: ('git', repo_url), ('hg', repo_url), or None.
    +   r   )githg   r   	bitbucketr   )splitlenr   )repo_urlrepo_url_values	repo_types      0lib/python3.12/site-packages/cookiecutter/vcs.pyidentify_repor      sq     nnS)O
?q #A&	%oa000!!H(?"H$>!!!    c                 *    t        t        |             S )zb
    Check if the version control system for a repo type is installed.

    :param repo_type:
    )boolr   )r   s    r   is_vcs_installedr   4   s     i !!r   r   checkoutclone_to_dirzos.PathLike[str]no_inputc                    t        |      j                         }t        |       t        |       \  }} t	        |      sd| d}t        |      | j                  d      } t        j                  j                  |       d   }|dk(  rc|j                  d      d   j                  d      d	   }t        j                  j                  t        j                  j                  ||            }|d
k(  r=t        j                  j                  t        j                  j                  ||            }t        j                  d        t        j                  j                  |      rt!        ||      }nd}|rr	 t#        j$                  |d| g|t"        j&                         |D|g}	|d
k(  r|	j)                  d	d       t#        j$                  |dg|	|t"        j&                         |S |S # t"        j*                  $ r}
|
j,                  j/                  d      dj1                         v rt3        d|  d      |
t5        fdt6        D              rt9        d| d|  d      |
t        j;                  d        d}
~
ww xY w)a  Clone a repo to the current directory.

    :param repo_url: Repo URL of unknown type.
    :param checkout: The branch, tag or commit ID to checkout after clone.
    :param clone_to_dir: The directory to clone to.
                         Defaults to the current directory.
    :param no_input: Do not prompt for user input and eventually force a refresh of
        cached resources.
    :returns: str with path to the new directory of the repository.
    'z' is not installed./r   r   :z.gitr   r   zrepo_dir is )r    Tclone)cwdstderrNz--r   zutf-8z	not foundzThe repository z* could not be found, have you made a typo?c              3   &   K   | ]  }|v  
 y w)N ).0erroroutputs     r   	<genexpr>zclone.<locals>.<genexpr>   s     >u5F?>s   zThe z branch of repository z' could not found, have you made a typo?zgit clone failed with error: %s)r   
expanduserr   r   r   r	   rstripospathr   rsplitnormpathjoinloggerdebugisdirr
   
subprocesscheck_outputSTDOUTinsertCalledProcessErrorr-   decodelowerr   anyBRANCH_ERRORSr   r,   )r   r   r   r    r   msg	repo_namerepo_dirr&   checkout_paramsclone_errorr-   s              @r   r&   r&   =   sY   " %002L,' (1Ix I&)/0c""s#Hh'*IEOOC(,33F;A>	77##BGGLLy$IJD77##BGGLLy$IJ
LL<z*+	ww}}X!(X>	##GX. !((
 ##+*$#**1d3''
=_= %,,( O8O ,, 	 ''..w7Fflln,(%hZ 0, , ## >>>+8*$:j GI ## LL:FC	s   7A/G* *J=A?I<<J)N.F)__doc__loggingr1   r9   pathlibr   shutilr   typingr   cookiecutter.exceptionsr   r   r   r	   cookiecutter.promptr
   cookiecutter.utilsr   	getLogger__name__r6   rA   r   r   strr   r&   r*   r   r   <module>rS      s    @  	      2 4			8	$ "0" #'*	JJsmJ %J 	Jr   