
    h                        S SK r S SKrS SKJr  S SKJr  S SKrS SKJr  SSK	J
r
  SSKJrJrJrJr  SS	KJrJrJrJrJrJr  \
R.                  r\
R2                  rS
S/r\R8                  " S5      \" SSS9\" SSSS9\" \SSSS9\" SSSSSR;                  \5       3S9\" SSSSS94S\R<                  S\S\\   S \S!\\   S"\ 4S# jj5       r!\
R.                  \
R2                  S\S$.S\S\S \S!\S"\ S%\S&S4S' jjr"S\S\S \S&S4S( jr#g))    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           	         Uc.  [         R                  " 5       [        U5      R                  S   -  nU[        :X  a	  Uc  [        nUcZ  [
         H  n[        X65      (       d  M  Un  O   Uc5  SR                  S [
         5       5      n[        R                  " SU S3SS9  O,[        X45      (       d  [        R                  " S	U S
U S3SS9  [        U[        5      (       d   e[        U 5      n[        UUUUUUS9  g)aC  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   .   #    U  H  nS U S 3v   M     g7f)'N ).0bs     J/home/james-whalen/.local/lib/python3.13/site-packages/weasel/cli/clone.py	<genexpr>$project_clone_cli.<locals>.<genexpr>/   s     ,P?O!q1X?Os   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_clir9      s    $ |xxzDJ,,R00|(~.N%d;;' / >#'99,P?O,P#P HH01A &d33HHvdV:fX5FGqQfc""""(-N'%    r+   r,   returnc          	         [        U5      n[        XU5        UR                  5       n[        R                  " SSU5      n [        X XUS9  [        R                  " S
U  SU SU S3U5        U[        -  R                  5       (       d  [        R                  " S[         S35        g[        R                  " S5        [        SU SU 35        g! [        R                   a$    SU  SU SU S3n[        R                  " USS	9   Nf = f)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   r3   goodr   r   warnprint)	r   r   r   r   r   r,   project_dir	repo_nameerrs	            r&   r6   r6   D   s      tDD!,,.K4b$?IT_M HHxvXi[F82FT,&..003|n$789-.+N+;8D6JK (( !$}YK{6(RTUAs   C 5DDc                 L   SU  SU SU S3n[        US9  U(       d  [        R                  " SU 3SS9  UR                  5       (       a  [        R                  " S	U 3SS9  UR                  R                  5       (       d$  [        R                  " S
UR                   S3SS9  gg)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   r3   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	
  r:   )$rA   rC   pathlibr   typingr   typerwasabir   r=   r   utilr   r	   r
   r   r   r   r   r   r   r   r   __projects__r/   __projects_branch__r0   r1   commandr2   Contextr5   boolr9   r6   r?   r#   r:   r&   <module>rY      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 
r:   