ó
'—^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 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
   BadCommand(   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(    (    s2   /tmp/pip-build-eiI0Wo/pip/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(    (    s2   /tmp/pip-build-eiI0Wo/pip/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(    (    s2   /tmp/pip-build-eiI0Wo/pip/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*   (    (    s2   /tmp/pip-build-eiI0Wo/pip/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   stripR/   R0   t   None(   t   clst   locationt   argst   outputt   ref(    (    s2   /tmp/pip-build-eiI0Wo/pip/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+   R7   N(   t   endswithR   t   unpackt   pathR.   R    (   R#   R;   R$   t   temp_dir(    (    s2   /tmp/pip-build-eiI0Wo/pip/pip/_internal/vcs/git.pyRB   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-refR7   R+   t   on_returncodet   ignores   unexpected show-ref line: {!r}s   refs/remotes/origin/{}s   refs/tags/{}N(
   R.   R    R8   t
   splitlinesR1   t
   ValueErrort   formatt   getR9   t   True(
   R:   R%   R   R=   t   refst   lineR   R>   t
   branch_reft   tag_ref(    (    s2   /tmp/pip-build-eiI0Wo/pip/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   -qR7   R   t
   FETCH_HEADN(   t   arg_revR9   t   AssertionErrorR"   t   make_newt   branch_nameR   t   loggert   warningR/   R.   R   t   to_argst   get_revision(   R:   R%   R$   R'   R   R   t	   is_branch(    (    s2   /tmp/pip-build-eiI0Wo/pip/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(    (    s2   /tmp/pip-build-eiI0Wo/pip/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   -qRW   t   checkoutR7   s	   origin/{}s   -bs   --track(   t
   to_displayRX   t   infoR   R.   R   R   R]   t   getattrR9   R!   RZ   R?   RK   t   update_submodules(   R#   R%   R$   R'   t   rev_displayRW   t   cmd_argst   track_branch(    (    s2   /tmp/pip-build-eiI0Wo/pip/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.urlR7   R_   s   -q(   R.   R   RZ   Rc   (   R#   R%   R$   R'   Re   (    (    s2   /tmp/pip-build-eiI0Wo/pip/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.0RR   s   -qs   --tagsR7   t   resets   --hard(   R5   R3   R.   R]   R   RZ   Rc   (   R#   R%   R$   R'   Re   (    (    s2   /tmp/pip-build-eiI0Wo/pip/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.
        Rh   s   --get-regexps   remote\..*\.urlR6   i   R+   R7   i    s   remote.origin.url t    (   i   (   R.   R    RI   t
   IndexErrorR	   R/   R1   R8   (   R:   R;   t   stdoutt   remotest   found_remotet   remoteR$   (    (    s2   /tmp/pip-build-eiI0Wo/pip/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+   R7   (   R9   R.   R    R8   (   R:   R;   R   t   current_rev(    (    s2   /tmp/pip-build-eiI0Wo/pip/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+   R7   s   ..(	   R.   R    R8   t   osRE   t   isabsR2   t   abspathR   (   R:   R;   t   git_dirt	   repo_root(    (    s2   /tmp/pip-build-eiI0Wo/pip/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   fileR@   s   \t   +i   s   ://s   file:s   git+s
   git+ssh://s   ssh://R,   (   t   urlsplitRC   R0   t   lstript   urllib_requestt   url2pathnamet   replacet
   urlunsplitt   findRU   t   superR   t   get_url_rev_and_auth(   R:   R$   t   schemet   netlocRE   t   queryt   fragmentt   initial_slashest   newpatht
   after_plusR   t	   user_pass(    (    s2   /tmp/pip-build-eiI0Wo/pip/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	   submoduleRk   s   --inits   --recursives   -qR7   (   Rt   RE   t   existsR2   R.   (   R:   R;   (    (    s2   /tmp/pip-build-eiI0Wo/pip/pip/_internal/vcs/git.pyRc   k  s
    !c      
   C@  sx   t  t |  ƒ j | ƒ r t Sy3 |  j d g d | d t d d d t ƒ} | SWn" t k
 rs t j d | ƒ t SXd  S(   Ns	   rev-parseR7   R+   RG   RH   t   log_failed_cmdsK   could not determine if %s is under git control because git is not available(	   Rƒ   R   t   controls_locationRM   R.   R    R   RX   t   debug(   R:   R;   t   r(    (    s2   /tmp/pip-build-eiI0Wo/pip/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)   R5   t   classmethodR?   RB   R"   R]   R!   Rg   Ri   Rk   Rr   R9   R[   Ry   R„   Rc   R   (    (    (    s2   /tmp/pip-build-eiI0Wo/pip/pip/_internal/vcs/git.pyR   .   s0   			#-			#	(-   t
   __future__R    t   loggingt   os.pathRt   t   ret   pip._vendor.packaging.versionR   R3   t   pip._vendor.six.moves.urllibt   urllib_parseR   R~   t   pip._internal.exceptionsR   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“   RX   t   compileR   R   R   t   register(    (    (    s2   /tmp/pip-build-eiI0Wo/pip/pip/_internal/vcs/git.pyt   <module>   s0   "			ÿ X