
    h                         S SK r S SKrS SKJr  S SKJr  S SKJr  SSKJ	r	  SSK
JrJr  SS	S
.S\S\S\S\S\4
S jjrS rS\S\S\4S jr SS\S\\\4   4S jjrS\S\4S jrg)    N)Path)Tuple)msg   )run_command)is_subpath_ofmake_tempdirmasterF)branchsparsereposubpathdestr   r   c                ^   [        5       nUR                  5       (       a  [        R                  " SSS9  UR                  R                  5       (       d  [        R                  " SSS9  U(       a  US:  a  [        XX#5      $ U(       a2  SUS    SUS    S	3nS
n[        R                  " US:X  a  UOU S35        [        5        nSU SU  SU 3n	[        U	SS9   U[        U5      -  n
[        X5      (       d  SU S3n[        R                  " XSS9  [        R                  R                  U
5      (       a  [        R                  " X5        O[        R                   " X5         S S S 5        g ! ["         a!    SU SU S3n[        R                  " XSS9   N3f = f! , (       d  f       g = f)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               I/home/james-whalen/.local/lib/python3.13/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6'"OP!,ww}}[))22 
 ! 	) 	)_`f_ggijCHHSa(	) 
s=   FA3E0FE0&F0(FFFF
F,c           	         [        5        nSU  SU SU S3n[        U5        SU SU 3n[        USS9n[        U 5      nSR                  UR                  R                  5        Vs/ s H  oR                  S	5      (       d  M  US
S  PM!     sn5      n	U	(       d!  SU SU  SU S	3n
[        R                  " U
S
S9  SU SU SU	 3n[        USS9  SU SU SU 3n[        USS9  U[        U5      -  n[        XK5      (       d  SU S3n
[        R                  " XS
S9  [        R                  " [        U5      [        U5      5        S S S 5        g s  snf ! , (       d  f       g = f)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     
7 ay ),. 	 	C y MgYW#t,%88CJJ,<,<,>T,>q,,sBSUQqrU,>TU9' CLLP6 R$XQ( 
 HHS"yXJazBC&y
6(!G9=C& W-W22gYKLCHHSa(C$c$i0C 
 U 
s%   AE'E
	E
B;EE
E$returnc                 \    [        5         SU  SU 3n[        USS9nUR                  S:g  nU$ )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                 6    [        SSS9nUR                  R	                  5       nU(       a  UR                  S5      (       d  gUSS R	                  5       R                  S5      n[        US	   5      [        US
   5      4$ ! [         a    [        U 5      ef = f)zGet 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9RSk!'',Gwqz?C
O++  "5!!"s   
B Bc                    U R                  S5      (       a  U R                  SS5      n U R                  S5      (       aC  U R                  SS5      R                  SSS5      n U R                  S5      (       a  U S S n U  S3n U $ )	Nzhttp://zhttps://zgit@/:r   z.git)r9   replaceendswith)r   s    r0   r5   r5      sy    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   