
    g                         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y)    )annotationsN)contextmanager)Path)TemporaryDirectory)TYPE_CHECKING)GitError)Iteratorzgriffe-worktree-c                    t        j                  d|       } t        j                  dd|       } t        j                  dd|       j	                  d      S )NNFKCz[^\w]+-z[-\s]+)unicodedata	normalizeresubstrip)values    @/var/www/openai/venv/lib/python3.12/site-packages/_griffe/git.py
_normalizer      sD    !!&%0EFF9c5)E66)S%(..s33    c                    t        j                  d      st        d      	 t        j                  ddt        |       ddgdt        j                  t        j                         y	# 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runstrDEVNULLCalledProcessErrorOSError)patherrs     r   assert_git_repor(      s     <<OPP@D#d)[2IJ%%%%		
 (( @.tf56C?@s   AA& &B9BBc                   t        | t              rt        |       } | j                         s| j                  } t        j                  g d| dt
        j                  t
        j                  d      }|j                  j                         }|j                  dk7  s|st        d|  d|xs d       |j                  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)repoprocessoutputs      r   get_latest_tagr9   6   s     $Dz;;={{nn3  G ^^!!#FQf1$r&:MI9NOPP<<a ##r   c                    t        | t              rt        |       } | j                         s| j                  } t        j                  g d|       }|j                         j                         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+   )	r/   r"   r   r0   r1   r    check_outputdecoder   )r6   r8   s     r   get_repo_rootr=   Q   sV     $Dz;;={{$$/F ==?  ""r   c              #    K   t        |        t        |       j                         j                  }t	        |      }t        t         | d| d      5 }t        j                  j                  ||      }d| }t        j                  dd| ddd|||g	d	d
      }|j                  r&t        d|j                  j                                	 t        |       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
       	 ddd       y# 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# 1 sw Y   yxY ww)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!   r4   r   r   r<   r#   )r6   ref	repo_namenormreftmp_dirlocation
tmp_branchr7   s           r   tmp_worktreerQ   e   s     DT
""$))IoG	&6%7	{!G9A#N	OSZ77<<1wi(
..D$
E4XsS

 !@AVAVAX@YZ[[	tx. NNE4z8XNWaWiWiqvwNNE4z7CJL^L^fklNNE4xzJS]SeSemrs! 
P	O NNE4z8XNWaWiWiqvwNNE4z7CJL^L^fklNNE4xzJS]SeSemrs! 
P	Os9   AG<A9G0E(BG0	G<(BG--G00G95G<)r   r"   returnr"   )r&   
str | PathrR   None)r6   rS   rR   r"   ).HEAD)r6   rS   rK   r"   rR   zIterator[Path])
__future__r   rI   r   r   r    r   
contextlibr   pathlibr   tempfiler   typingr   _griffe.exceptionsr   collections.abcr	   rH   r   r(   r9   r=   rQ    r   r   <module>r_      s_   
 # 	 	    %  '   '(% 4@.$6#( !t !tr   