
    -h                         d dl mZ d dlZd dl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 d dlmZ erd dlmZ d	ZddZddZddZddZeddd            ZdS )    )annotationsN)contextmanager)Path)TemporaryDirectory)TYPE_CHECKING)GitError)Iteratorzgriffe-worktree-valuestrreturnc                    t          j        d|           } t          j        dd|           } t          j        dd|                               d          S )NNFKCz[^\w]+-z[-\s]+)unicodedata	normalizeresubstrip)r
   s    H/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/_griffe/git.py
_normalizer      sI    !&%00EF9c5))E6)S%((..s333    path
str | PathNonec                   t          j        d          st          d          	 t          j        ddt          |           ddgdt          j        t          j                   d	S # t          j        $ r}t          d|            |d	}~ww xY w)
zAssert that a directory is a Git repository.

    Parameters:
        path: Path to a directory.

    Raises:
        OSError: When the directory is not a Git repository.
    gitz2Could not find git executable. Please install git.-C	rev-parsez--is-inside-work-treeT)checkstdoutstderrzNot a git repository: N)	shutilwhichRuntimeError
subprocessrunr   DEVNULLCalledProcessErrorOSError)r   errs     r   assert_git_repor+      s     < QOPPP@D#d))[2IJ%%		
 	
 	
 	
 	
 	
 ( @ @ @5t5566C?@s   >A% %B4BBrepoc                   t          | t                    rt          |           } |                                 s| j        } t          j        g d| dt
          j        t
          j        d          }|j	        
                                }|j        dk    s|st          d|  d|pd           |                    d	d
          d         S )zGet latest tag of a Git repository.

    Parameters:
        repo: The path to Git repository.

    Returns:
        The latest tag.
    )r   tagz-lz--sort=-creatordateTF)cwdtextr    r!   r   r   zCannot list Git tags in z: zno tags
   )
isinstancer   r   is_dirparentr%   r&   PIPESTDOUTr    r   
returncoder   split)r,   processoutputs      r   get_latest_tagr<   6   s     $ Dzz;;== {n333   G ^!!##FQfO$OO&:MIOOPPP<<a  ##r   c                    t          | t                    rt          |           } |                                 s| j        } t          j        g d|           }|                                                                S )zGet the root of a Git repository.

    Parameters:
        repo: The path to a Git repository.

    Returns:
        The root of the repository.
    )r   r   z--show-toplevel)r/   )	r3   r   r   r4   r5   r%   check_outputdecoder   )r,   r;   s     r   get_repo_rootr@   Q   sw     $ Dzz;;== {$///  F ==??  """r   .HEADrefIterator[Path]c              #    K   t          |            t          |                                           j        }t	          |          }t          t           | d| d          5 }t          j        	                    ||          }d| }t          j        dd| ddd|||g	d	d
          }|j        r)t          d|j                                                   	 t          |          V  t          j        dd| dd|gt          j        d
           t          j        dd| ddgt          j        d
           t          j        dd| dd|gt          j        d
           ny# t          j        dd| dd|gt          j        d
           t          j        dd| ddgt          j        d
           t          j        dd| dd|gt          j        d
           w xY w	 ddd           dS # 1 swxY w Y   dS )a  Context manager that checks out the given reference in the given repository to a temporary worktree.

    Parameters:
        repo: Path to the repository (i.e. the directory *containing* the `.git` directory)
        ref: A Git reference such as a commit, tag or branch.

    Yields:
        The path to the temporary worktree.

    Raises:
        OSError: If `repo` is not a valid `.git` repository
        RuntimeError: If the `git` executable is unavailable, or if it cannot create a worktree
    r   )prefixzgriffe-r   r   worktreeaddz-bTF)capture_outputr   zCould not create git worktree: remove)r    r   prunebranchz-DN)r+   r   resolvenamer   r   _WORKTREE_PREFIXosr   joinr%   r&   r8   r$   r!   r?   r'   )r,   rC   	repo_namenormreftmp_dirlocation
tmp_branchr:   s           r   tmp_worktreerW   e   sv      DT

""$$)IooG	&6#N	#N#NG#N#N#N	O	O	O tSZ7<<11(w((
.D$
E4XsS
 
 

  	\ZAVAVAXAXZZ[[[	tx..   NE4z8XNWaWiqvwwwwNE4z7CJL^fkllllNE4xzJS]Semrsssss NE4z8XNWaWiqvwwwwNE4z7CJL^fkllllNE4xzJS]Semrssssss!t t t t t t t t t t t t t t t t t ts-   $A6G(E!,A5G(!A6GG((G,/G,)r
   r   r   r   )r   r   r   r   )r,   r   r   r   )rA   rB   )r,   r   rC   r   r   rD   )
__future__r   rP   r   r"   r%   r   
contextlibr   pathlibr   tempfiler   typingr   _griffe.exceptionsr   collections.abcr	   rO   r   r+   r<   r@   rW    r   r   <module>r`      sP  
 # " " " " " 				 				          % % % % % %       ' ' ' ' ' '             ' ' ' ' ' ' )((((((% 4 4 4 4@ @ @ @.$ $ $ $6# # # #( !t !t !t !t !t !t !tr   