U ��.e5�@sddlmZddlZddlZddlZddlmZddl mZ ddl m Z ddl mZddlmZddlmZddlmZdd lmZdd lmZmZmZmZer�dd lmZmZdd lmZdd lm Z m!Z!e j"Z"e j#Z#e�$e%�Z&e�'d�Z(dd�Z)Gdd�de�Z*e�+e*�dS)�)�absolute_importN)�parse)�request)� BadCommand)� display_path)� make_command)� TempDirectory)�MYPY_CHECK_RUNNING)�RemoteNotFoundError�VersionControl�!find_path_to_setup_from_repo_root�vcs)�Optional�Tuple)� HiddenText)�AuthInfo� RevOptionsz^[a-fA-F0-9]{40}$cCstt�|��S�N)�bool� HASH_REGEX�match)�sha�r�9/usr/lib/python3.8/site-packages/pip/_internal/vcs/git.py�looks_like_hash*srcs�eZdZdZdZdZdZdZdZe dd��Z d d �Z e d d ��Z d d�Ze dd��Ze dd��Ze dd��Zdd�Zdd�Zdd�Ze dd��Ze d(dd��Ze d d!��Ze �fd"d#��Ze d$d%��Ze �fd&d'��Z�ZS))�Git�gitz.git�clone)rzgit+httpz git+httpszgit+sshzgit+gitzgit+file)ZGIT_DIRZ GIT_WORK_TREE�HEADcCs|gSrr��revrrr�get_base_rev_args:szGit.get_base_rev_argscCs\d}|jdgdd�}|�|�r8|t|�d���d}nd}d�|�d�dd��}t|�S) Nz git version �versionF)� show_stdoutr��.�)� run_command� startswith�len�split�join� parse_version)�selfZ VERSION_PFXr"rrr�get_git_version>s zGit.get_git_versioncCsBdddg}|j|dd|d�}|��}|�d�r>|td�d�SdS) zl Return the current branch, or None if HEAD isn't at a branch (e.g. detached HEAD). z symbolic-ref�-qr��F�Zextra_ok_returncodesr#�cwdz refs/heads/N)r'�stripr(r))�cls�location�args�output�refrrr�get_current_branchKs � zGit.get_current_branchc CsX|�d�s|d}tdd��2}|j|j|d�|jdddd|gd |jd �W5QRXd S) z@Export the Git repository at the url to the destination location�/�export)Zkind)�urlzcheckout-indexz-az-fz--prefixF�r#r3N)�endswithr�unpack�pathr')r-r6r=Ztemp_dirrrrr<`s   �z Git.exportc Cs�|jd|g|ddd�}i}|���d�D]V}|�d�}|s)r'r4)r5r6r Z current_revrrrrU%s�zGit.get_revisioncCsR|jddgd|d���}tj�|�s2tj�||�}tj�tj�|d��}t||�S)z~ Return the path to setup.py, relative to the repo root. Return None if setup.py is in the repo root. riz --git-dirFr>z..)r'r4�osrA�isabsr+�abspathr )r5r6Zgit_dirZ repo_rootrrr�get_subdirectory.s�  zGit.get_subdirectoryc s�t|�\}}}}}|�d�r�|dt|�d�� �}|t�|��dd��d�}t|||||f�}|�d�d} |d| �t|| d�||||f�}d|kr�|�dd �}t t |�� |�\}} } |�d d �}nt t |�� |�\}} } || | fS) a9 Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'. That's required because although they use SSH they sometimes don't work with a ssh:// scheme (e.g. GitHub). But we need a scheme for parsing. Hence we remove it again afterwards and return it as a stub. �fileNr;�\�+r1z://zgit+z git+ssh://zssh://r$) �urlsplitr?r)�lstrip�urllib_requestZ url2pathname�replace� urlunsplit�find�superr�get_url_rev_and_auth) r5r=ZschemeZnetlocrAZqueryZfragment�initial_slashes�newpathZ after_plusr Z user_pass�� __class__rrrx=s.   ���� � zGit.get_url_rev_and_authcCs6tj�tj�|d��sdS|jdddddg|d�dS)Nz .gitmodulesZ submodulerdz--initz --recursiver/rQ)rjrA�existsr+r')r5r6rrrr]`s  �zGit.update_submodulescsZtt|��|�rdSz|jdg|dddd�}| WStk rTt�d|�YdSXdS)NTriFrB)r3r#rCZlog_failed_cmdzKcould not determine if %s is under git control because git is not available)rwr�controls_locationr'rrS�debug)r5r6�rr{rrr~is��zGit.controls_location)N)�__name__� __module__� __qualname__rX�dirnameZ repo_nameZschemesZ unset_environZdefault_arg_rev� staticmethodr!r.� classmethodr:r<rOrWrYr_rbrdrhrUrmrxr]r~� __classcell__rrr{rr.sB     ( ,     " r),Z __future__rZloggingZos.pathrj�reZpip._vendor.packaging.versionrr,Zpip._vendor.six.moves.urllibZ urllib_parserrsZpip._internal.exceptionsrZpip._internal.utils.miscrZpip._internal.utils.subprocessrZpip._internal.utils.temp_dirrZpip._internal.utils.typingr Z pip._internal.vcs.versioncontrolr r r r �typingrrrrrrqruZ getLoggerr�rS�compilerrr�registerrrrr�s2            N