
    i                         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	 ddl
mZmZ dd	d
dededededef
dZd ZdededefdZ	 ddedeeef   fdZdedefdZy)    N)Path)Tuple)msg   )run_command)is_subpath_ofmake_tempdirmasterF)branchsparsereposubpathdestr   r   c                .   t               }|j                         rt        j                  dd       |j                  j                         st        j                  dd       |r|dk\  rt        | |||      S |r0d|d    d|d    d	}d
}t        j                  |dk(  r|n| d       t               5 }d| d|  d| }	t        |	d       	 |t        |      z  }
t        ||
      sd| d}t        j                  || d       t        j                  j                  |
      rt        j                  |
|       nt        j                   |
|       d d d        y # t"        $ r$ d| d| d}t        j                  || d       Y 5w xY w# 1 sw Y   y xY w)Nz&Destination of checkout must not existr   exitsz,Parent of destination of checkout must exist)      z'You're running an old version of Git (vr   .z1) that doesn't fully support sparse checkout yet.zOYou're running an unknown version of Git, so sparse checkout has been disabled.r   r   z This means that more files than necessary may be downloaded temporarily. To only download the files needed, make sure you're using Git v2.22 or above.git -C z clone z . -b Tcapture'-' is a path outside of the cloned repository.zCan't clone z6. Make sure the directory exists in the repo (branch 'z'))get_git_versionexistsr   failparentgit_sparse_checkoutwarnr	   r   r   r   ospathisdirshutilcopytreecopyfileFileNotFoundError)r   r   r   r   r   git_versionerr_olderr_unktmp_dircmdsource_patherrs               `/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/weasel/util/git.pygit_checkoutr1      s    "#K{{}9C;;?qI+("4$??	 6k!n5EQ{ST~FV W> ? 	 d%/wW= >/ 0	
 
 )7yvVF8<C&	)!DM1K +6'"OPd!,ww}}[)T2T2) ) ! 	) 	)_`f_ggijCHHS$a(	)) )s+   4FBE*FFFFFc           	         t               5 }d|  d| d| d}t        |       d| d| }t        |d      }t        |       }dj                  |j                  j                         D cg c]  }|j                  d	      s|d
d   c}      }	|	s#d| d|  d| d	}
t        j                  |
d
       d| d| d|	 }t        |d       d| d| d| }t        |d       |t        |      z  }t        ||      sd| d}
t        j                  |
| d
       t        j                  t        |      t        |             d d d        y c c}w # 1 sw Y   y xY w)Nz
git clone  z --no-checkout --depth 1 -b z --filter=blob:noner   z- rev-list --objects --all --missing=print -- Tr   ?r   z'Could not find any relevant files for 'z<'. Did you specify a correct and complete path within repo 'z' and branch r   z fetch-pack z
 checkout r   r   )r	   r   _http_to_gitjoinstdoutsplit
startswithr   r   r   r   r%   movestr)r   r   r   r   r,   r-   retgit_repoxmissingsr/   r.   s               r0   r    r    6   s     
 !17 ay ),. 	 	C y MgYW#t,%88CJJ,<,<,>Tq!,,sBSQqrUTU9' CLLP6 R$XQ( 
 HHS"yXJazBC&y
6(!G9=C& W-Wk2gYKLCHHS$a(C$c$i0C!1 !1 U!1 !1s%   AE*E
E
B<EEEreturnc                 b    t                d|  d| }t        |d      }|j                  dk7  }|S )zUses 'git ls-remote' to check if a repository and branch exists

    repo (str): URL to get repo.
    branch (str): Branch on repo to check.
    RETURNS (bool): True if repo:branch exists.
    zgit ls-remote r3   Tr    )r   r   r7   )r   r   r-   r<   r   s        r0   git_repo_branch_existsrC   j   s=     4&&
*C c4
(CZZ2FM    errorc                 &   	 t        dd      }|j                  j	                         }|r|j                  d      sy|dd j	                         j                  d      }t        |d	         t        |d
         fS # t        $ r t        |       w xY w)a  Get the version of git and raise an error if calling 'git --version' fails.

    error (str): The error message to show.
    RETURNS (Tuple[int, int]): The version as a (major, minor) tuple. Returns
        (0, 0) if the version couldn't be determined.
    zgit --versionTr   zgit versionr      Nr   r   r   )r   	ExceptionRuntimeErrorr7   stripr9   r8   int)rE   r<   r7   versions       r0   r   r   {   s    "/48 ZZF**=9RSk!'',Gwqz?C
O++  "5!!"s   A; ;Bc                     | j                  d      r| j                  dd      } | j                  d      r>| j                  dd      j                  ddd      } | j                  d      r| d d } |  d} | S )	Nzhttp://zhttps://zgit@/:r   z.git)r9   replaceendswith)r   s    r0   r5   r5      sp    y!||J4{#||J/77S!D==9Dt}KrD   )zNCould not run 'git'. Make sure it's installed and the executable is available.)r"   r%   pathlibr   typingr   wasabir   commandsr   
filesystemr   r	   r;   boolr1   r    rC   rK   r   r5    rD   r0   <module>rZ      s    	     ! 3 ;CSX')
')')#'')47')LP')T11h c d $ b,,
38_,(s s rD   