
    i                     $   d dl Z d dlZd dlmZ d dlmZ d dl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mZmZmZmZ e
j.                  Ze
j2                  Zd
dgZ ej8                  d       edd       eddd       eeddd       edddddj;                  e              edddd      fdej<                  dedee   d ed!ee   d"e fd#       Z!e
j.                  e
j2                  ded$deded ed!ed"e d%ed&dfd'Z"deded ed&dfd(Z#y))    N)Path)Optional)msg   )about)ensure_pathget_git_versiongit_checkoutgit_repo_branch_exists   )COMMANDPROJECT_FILEArgOpt_get_parent_commandappmainmasterclone.z!The name of the template to clone)helpzAWhere to clone the project. Defaults to current working directoryF)r   existsz--repoz-rzThe repository to clone fromz--branchz-bz8The branch to clone from. If not provided, will attempt , z--sparsez-SzZUse sparse Git checkout to only check out and clone the files needed. Requires Git v22.2+.ctxnamedestrepobranchsparse_checkoutc                    |-t        j                         t        |      j                  d   z  }|t        k(  r|t        }|Ut
        D ]  }t        ||      s|} n |bdj                  d t
        D              }t        j                  d| dd       n*t        ||      st        j                  d	| d
| dd       t        |t              sJ t        |       }t        ||||||       y)aW  Clone a project template from a repository. Calls into "git" and will
    only download the files from the given subdirectory. The GitHub repo
    defaults to the official Weasel template repo, but can be customized
    (including using a private repo).

    DOCS: https://github.com/explosion/weasel/tree/main/docs/cli.md#clipboard-clone
    Nr   c              3   (   K   | ]
  }d | d   yw)'N ).0bs     a/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/weasel/cli/clone.py	<genexpr>z$project_clone_cli.<locals>.<genexpr>/   s     ,P!q1X,Ps   z2No branch provided and attempted default branches z do not exist.r   exitszrepo: z
 (branch: z) does not exist.r   r   r   parent_command)r   cwdpartsDEFAULT_REPODEFAULT_PROJECTS_BRANCHDEFAULT_BRANCHESr   joinr   fail
isinstancestrr   project_clone)	r   r   r   r   r   r   default_branchdefault_branches_msgr+   s	            r&   project_clone_clir8      s    $ |xxzDJ,,R00|(~. 	N%dN;'	 >#'99,P?O,P#P HH01A &dF3HHvdV:fX5FGqQfc"""(-N'%    r*   r+   returnc          	         t        |      }t        | ||       |j                         }t        j                  dd|      }	 t        || |||       t        j                  d
|  d| d| d|       |t        z  j                         st        j                  dt         d       yt        j                  d       t        d| d|        y# t        j                  $ r& d|  d| d| d}t        j                  |d	       Y w xY w)zClone a project template from a repository.

    name (str): Name of subdirectory to clone.
    dest (Path): Destination path of cloned project.
    repo (str): URL of Git repo containing project templates.
    branch (str): The branch to clone from
    z(http(s?)):\/\/github.com/ )r   sparsezCould not clone 'z' from repo 'z' (branch 'z')r   r(   zCloned 'z' from 'zNo z found in directoryzYour project is now ready!zTo fetch the assets, run:
z assets N)r   check_cloneresolveresubr
   
subprocessCalledProcessErrorr   r2   goodr   r   warnprint)	r   r   r   r   r   r+   project_dir	repo_nameerrs	            r&   r5   r5   D   s      tDdD!,,.K4b$?IT4f_M HHxvXi[F82FT,&..03|n$789-.+N+;8D6JK (( !$}YK{6(RTUAs   C 6DDc                 @   d|  d| d| d}t        |       |st        j                  d| d       |j                         rt        j                  d	| d       |j                  j                         s&t        j                  d
|j                   dd       yy)a=  Check and validate that the destination path can be used to clone. Will
    check that Git is available and that the destination path is suitable.

    name (str): Name of the directory to clone from the repo.
    dest (Path): Local destination of cloned directory.
    repo (str): URL of the repo to clone from.
    z~Cloning Weasel project templates requires Git and the 'git' command. To clone a project without Git, copy the files from the 'z' directory in the z to z
 manually.)errorz(Not a valid directory to clone project: r   r(   z/Can't clone project, directory already exists: z5Can't clone project, parent directory doesn't exist: z9. Create the necessary folder(s) first before continuing.N)r	   r   r2   r   parent)r   r   r   git_errs       r&   r>   r>   e   s    DDH6 J 6dV:	7 
 '";D6B!L{{}B4&IQRS;;CDKK= QF G	
  r9   )$r@   rB   pathlibr   typingr   typerwasabir   r<   r   utilr   r	   r
   r   r   r   r   r   r   r   r   __projects__r.   __projects_branch__r/   r0   commandr1   Contextr4   boolr8   r5   r>   r#   r9   r&   <module>rX      s   	       U U K K!!33 H%  W CABt*mv{|L(D7UVj$?wx|  yB  yB  CS  yT  xU  >V  Wz4  ?[  \.	. . 4.	.
 . SM. . .j ""++!!L
L
L 	L
 L L L 
LB
c 
 
S 
T 
r9   