ó
j·Ã^c           @@  s‡  d  d l  m 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 m Z d  d l m Z m Z d  d l m Z d  d l m Z d  d	 l m Z d  d
 l m Z m Z m Z m Z e r'd  d l m Z m  Z  d  d l m! Z! d  d l m" Z" m# Z# n  e
 j$ Z$ e
 j% Z% e j& e' ƒ Z( e j) d ƒ Z* d „  Z+ d e f d „  ƒ  YZ, e j- e, ƒ d S(   i    (   t   absolute_importN(   t   parse(   t   request(   t
   BadCommandt   InstallationError(   t   display_patht   hide_url(   t   make_command(   t   TempDirectory(   t   MYPY_CHECK_RUNNING(   t   RemoteNotFoundErrort   VersionControlt!   find_path_to_setup_from_repo_roott   vcs(   t   Optionalt   Tuple(   t
   HiddenText(   t   AuthInfot
   RevOptionss   ^[a-fA-F0-9]{40}$c         C@  s   t  t j |  ƒ ƒ S(   N(   t   boolt
   HASH_REGEXt   match(   t   sha(    (    s&   site-packages/pip/_internal/vcs/git.pyt   looks_like_hash*   s    t   Gitc           B@  s
  e  Z d  Z d Z d Z d Z d Z d
 Z e d „  ƒ Z	 d „  Z
 d „  Z e d „  ƒ Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z d „  Z e d „  ƒ Z e d d „ ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   t   gits   .gitt   clones   git+https	   git+httpss   git+sshs   git+gits   git+filet   GIT_DIRt   GIT_WORK_TREEt   HEADc         C@  s   |  g S(   N(    (   t   rev(    (    s&   site-packages/pip/_internal/vcs/git.pyt   get_base_rev_args:   s    c         C@  se   |  j  t | ƒ ƒ \ } } | j s( t S|  j | | j ƒ sA t St |  j | | j ƒ d ƒ } | S(   Ni    (   t   get_url_rev_optionsR   R   t   Falset   is_commit_id_equalR   t   get_revision_sha(   t   selft   urlt   destt   _t   rev_optionst   is_tag_or_branch(    (    s&   site-packages/pip/_internal/vcs/git.pyt   is_immutable_rev_checkout>   s    	c         C@  sv   d } |  j  d g d t ƒ} | j | ƒ rJ | t | ƒ j ƒ  d } n d } d j | j d ƒ d  ƒ } t | ƒ S(   Ns   git version t   versiont   show_stdouti    t    t   .i   (   t   run_commandR!   t
   startswitht   lent   splitt   joint   parse_version(   R$   t   VERSION_PFXR+   (    (    s&   site-packages/pip/_internal/vcs/git.pyt   get_git_versionO   s    c         C@  s]   d d d g } |  j  | d d	 d t d | ƒ} | j ƒ  } | j d ƒ rY | t d ƒ Sd
 S(   sl   
        Return the current branch, or None if HEAD isn't at a branch
        (e.g. detached HEAD).
        s   symbolic-refs   -qR   t   extra_ok_returncodesi   R,   t   cwds   refs/heads/(   i   N(   R/   R!   t   stripR0   R1   t   None(   t   clst   locationt   argst   outputt   ref(    (    s&   site-packages/pip/_internal/vcs/git.pyt   get_current_branch\   s    
c      
   C@  sy   | j  d ƒ s | d } n  t d d ƒ H } |  j | j d | ƒ|  j d d d d | g d	 t d
 | j ƒWd QXd S(   s@   Export the Git repository at the url to the destination locationt   /t   kindt   exportR%   s   checkout-indexs   -as   -fs   --prefixR,   R8   N(   t   endswithR   t   unpackt   pathR/   R!   (   R$   R<   R%   t   temp_dir(    (    s&   site-packages/pip/_internal/vcs/git.pyRC   q   s    c   
      C@  sï   |  j  d | g d | d t d d ƒ} i  } xc | j ƒ  j ƒ  D]O } y | j ƒ  \ } } Wn& t k
 r„ t d j | ƒ ƒ ‚ n X| | | <q@ Wd j | ƒ } d j | ƒ }	 | j | ƒ } | d	 k	 rÖ | t	 f S| j |	 ƒ } | t f S(
   sö   
        Return (sha_or_none, is_branch), where sha_or_none is a commit hash
        if the revision names a remote branch or tag, otherwise None.

        Args:
          dest: the repository directory.
          rev: the revision name.
        s   show-refR8   R,   t   on_returncodet   ignores   unexpected show-ref line: {!r}s   refs/remotes/origin/{}s   refs/tags/{}N(
   R/   R!   R9   t
   splitlinesR2   t
   ValueErrort   formatt   getR:   t   True(
   R;   R&   R   R>   t   refst   lineR   R?   t
   branch_reft   tag_ref(    (    s&   site-packages/pip/_internal/vcs/git.pyR#   ~   s     
c         C@  sé   | j  } | d k	 s t ‚ |  j | | ƒ \ } } | d k	 rg | j | ƒ } | rZ | n d | _ | St | ƒ s† t j d | ƒ n  | j	 d ƒ s™ | S|  j
 t d d | | j ƒ  ƒ d | ƒ|  j | d d ƒ} | j | ƒ } | S(	   sµ   
        Resolve a revision to a new RevOptions object with the SHA1 of the
        branch, tag, or ref if found.

        Args:
          rev_options: a RevOptions object.
        s:   Did not find branch or tag '%s', assuming revision or ref.s   refs/t   fetchs   -qR8   R   t
   FETCH_HEADN(   t   arg_revR:   t   AssertionErrorR#   t   make_newt   branch_nameR   t   loggert   warningR0   R/   R   t   to_argst   get_revision(   R;   R&   R%   R(   R   R   t	   is_branch(    (    s&   site-packages/pip/_internal/vcs/git.pyt   resolve_revision¡   s&    
	
c         C@  s   | s
 t  S|  j | ƒ | k S(   s§   
        Return whether the current commit hash equals the given name.

        Args:
          dest: the repository directory.
          name: a string name.
        (   R!   R\   (   R;   R&   t   name(    (    s&   site-packages/pip/_internal/vcs/git.pyR"   Î   s    	c         C@  s)  | j  ƒ  } t j d | | t | ƒ ƒ |  j t d d | | ƒ ƒ | j r|  j | | | ƒ } t | d d  ƒ } | d  k rÆ |  j
 | | j ƒ st d d | j ƒ  ƒ } |  j | d | ƒqq|  j | ƒ | k rd j | ƒ } d d | d	 | g } |  j | d | ƒqn  |  j | ƒ d  S(
   Ns   Cloning %s%s to %sR   s   -qRX   t   checkoutR8   s	   origin/{}s   -bs   --track(   t
   to_displayRY   t   infoR   R/   R   R   R^   t   getattrR:   R"   R[   R@   RL   t   update_submodules(   R$   R&   R%   R(   t   rev_displayRX   t   cmd_argst   track_branch(    (    s&   site-packages/pip/_internal/vcs/git.pyt	   fetch_newÝ   s     	c         C@  s[   |  j  t d d | ƒ d | ƒt d d | j ƒ  ƒ } |  j  | d | ƒ|  j | ƒ d  S(   Nt   configs   remote.origin.urlR8   R`   s   -q(   R/   R   R[   Rd   (   R$   R&   R%   R(   Rf   (    (    s&   site-packages/pip/_internal/vcs/git.pyt   switchû   s    c         C@  s¤   |  j  ƒ  t d ƒ k r7 |  j d d d g d | ƒn |  j d d g d | ƒ|  j | | | ƒ } t d d d | j ƒ  ƒ } |  j | d | ƒ|  j | ƒ d  S(   Ns   1.9.0RS   s   -qs   --tagsR8   t   resets   --hard(   R6   R4   R/   R^   R   R[   Rd   (   R$   R&   R%   R(   Rf   (    (    s&   site-packages/pip/_internal/vcs/git.pyt   update  s    c         C@  s¥   |  j  d d d g d d d t d | ƒ} | j ƒ  } y | d } Wn t k
 r] t ‚ n Xx' | D] } | j d	 ƒ re | } Pqe qe W| j d
 ƒ d } | j ƒ  S(   s¢   
        Return URL of the first remote encountered.

        Raises RemoteNotFoundError if the repository does not have a remote
        url configured.
        Ri   s   --get-regexps   remote\..*\.urlR7   i   R,   R8   i    s   remote.origin.url t    (   i   (   R/   R!   RJ   t
   IndexErrorR
   R0   R2   R9   (   R;   R<   t   stdoutt   remotest   found_remotet   remoteR%   (    (    s&   site-packages/pip/_internal/vcs/git.pyt   get_remote_url  s    

c         C@  s@   | d  k r d } n  |  j d | g d t d | ƒ} | j ƒ  S(   NR   s	   rev-parseR,   R8   (   R:   R/   R!   R9   (   R;   R<   R   t   current_rev(    (    s&   site-packages/pip/_internal/vcs/git.pyR\   0  s
    	c         C@  s   |  j  d d g d t d | ƒj ƒ  } t j j | ƒ sQ t j j | | ƒ } n  t j j t j j | d ƒ ƒ } t | | ƒ S(   s~   
        Return the path to setup.py, relative to the repo root.
        Return None if setup.py is in the repo root.
        s	   rev-parses	   --git-dirR,   R8   s   ..(	   R/   R!   R9   t   osRF   t   isabsR3   t   abspathR   (   R;   R<   t   git_dirt	   repo_root(    (    s&   site-packages/pip/_internal/vcs/git.pyt   get_subdirectory9  s    !c         C@  sX  t  | ƒ \ } } } } } | j d ƒ rÄ | t | j d ƒ ƒ  } | t j | ƒ j d d ƒ j d ƒ } t | | | | | f ƒ } | j d ƒ d }	 | |	  t | |	 | | | | f ƒ } n  d | k r*d | k sâ t	 ‚ | j d d	 ƒ } t
 t |  ƒ j | ƒ \ } }
 } | j d
 d ƒ } n! t
 t |  ƒ j | ƒ \ } }
 } | |
 | f S(   s9  
        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.
        t   fileRA   s   \t   +i   s   ://s   file:s   git+s
   git+ssh://s   ssh://R-   (   t   urlsplitRD   R1   t   lstript   urllib_requestt   url2pathnamet   replacet
   urlunsplitt   findRV   t   superR   t   get_url_rev_and_auth(   R;   R%   t   schemet   netlocRF   t   queryt   fragmentt   initial_slashest   newpatht
   after_plusR   t	   user_pass(    (    s&   site-packages/pip/_internal/vcs/git.pyR…   H  s"    
 !!c         C@  sK   t  j j t  j j | d ƒ ƒ s% d  S|  j d d d d d g d | ƒd  S(   Ns   .gitmodulest	   submoduleRl   s   --inits   --recursives   -qR8   (   Ru   RF   t   existsR3   R/   (   R;   R<   (    (    s&   site-packages/pip/_internal/vcs/git.pyRd   k  s
    !c      
   C@  s¢   t  t |  ƒ j | ƒ } | r" | Sy1 |  j d d g d | d t d d d t ƒ} Wn3 t k
 rw t j d | ƒ d  St	 k
 rˆ d  SXt
 j j | j d	 ƒ ƒ S(
   Ns	   rev-parses   --show-toplevelR8   R,   RH   t   raiset   log_failed_cmdsK   could not determine if %s is under git control because git is not availables   
(   R„   R   t   get_repository_rootR/   R!   R   RY   t   debugR:   R   Ru   RF   t   normpatht   rstrip(   R;   R<   t   loct   r(    (    s&   site-packages/pip/_internal/vcs/git.pyR’   t  s"    	(   R   s   git+https	   git+httpss   git+sshs   git+gits   git+file(   R   R   N(   t   __name__t
   __module__R_   t   dirnamet	   repo_namet   schemest   unset_environt   default_arg_revt   staticmethodR   R*   R6   t   classmethodR@   RC   R#   R^   R"   Rh   Rj   Rl   Rs   R:   R\   Rz   R…   Rd   R’   (    (    (    s&   site-packages/pip/_internal/vcs/git.pyR   .   s0   			#-			#	(.   t
   __future__R    t   loggingt   os.pathRu   t   ret   pip._vendor.packaging.versionR   R4   t   pip._vendor.six.moves.urllibt   urllib_parseR   R   t   pip._internal.exceptionsR   R   t   pip._internal.utils.miscR   R   t   pip._internal.utils.subprocessR   t   pip._internal.utils.temp_dirR   t   pip._internal.utils.typingR	   t    pip._internal.vcs.versioncontrolR
   R   R   R   t   typingR   R   R   R   R   R}   R‚   t	   getLoggerR˜   RY   t   compileR   R   R   t   register(    (    (    s&   site-packages/pip/_internal/vcs/git.pyt   <module>   s0   "			ÿ ]