
    E^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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dS )z:Helper functions for working with version control systems.    N)Path)which)Optional)RepositoryCloneFailedRepositoryNotFoundUnknownRepoTypeVCSNotInstalled)make_sure_path_existsprompt_and_deletezerror: pathspeczunknown revisionc                     |                      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.11/site-packages/cookiecutter/vcs.pyidentify_repor      s     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   2   s     i  !!!r   .Fr   checkoutclone_to_dirzos.PathLike[str]no_inputc                    t          |                                          }t          |           t          |           \  }} t	          |          sd| d}t          |          |                     d          } t          j        	                    |           d         }|dk    rq|	                    d          d         
                    d          d	         }t          j                            t          j                            ||                    }|d
k    r=t          j                            t          j                            ||                    }t                              d|            t          j                            |          rt!          ||          }nd}|r	 t#          j        |d| g|t"          j                   |D|g}	|d
k    r|	                    d	d           t#          j        |dg|	|t"          j                   n# t"          j        $ r}
|
j                            d          d                                v rt3          d|  d          |
t5          fdt6          D                       rt9          d| d|  d          |
t                              d            d}
~
ww xY w|S )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 V  	d S )N ).0erroroutputs     r   	<genexpr>zclone.<locals>.<genexpr>}   s'      >>u5F?>>>>>>r   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'   ;   s	   " %%0022L,''' (11Ix I&& #0)000c"""s##Hh''*IEOOC((,33F;;A>	7##BGLLy$I$IJJD7##BGLLy$I$IJJ
LL***+++	w}}X !(X>>> 	#GX. !(   
 ##+*$$#**1d333'
=_= %,   
 , 	 	 	 '..w77Ffllnn,,(,h , , ,  ## >>>>>>>>> #+I8 I II I I  ## LL:FCCC	 Os   0A*H K*BKK)Nr   F)__doc__loggingr2   r:   pathlibr   shutilr   typingr   cookiecutter.exceptionsr   r   r   r	   cookiecutter.utilsr
   r   	getLogger__name__r7   rB   r   r   strr   r'   r+   r   r   <module>rR      sV   @ @  				                                  H G G G G G G G		8	$	$ " " "0" " " #'*	J JJsmJ %J 	J J J J J Jr   