ó
Ð²Ebc           @@  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(    (    s2   /tmp/pip-build-UPPWic/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 e d „  ƒ Z d „  Z d „  Z d „  Z e 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-UPPWic/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-UPPWic/pip/pip/_internal/vcs/git.pyt   is_immutable_rev_checkout?   s    	c         C@  s|   d } |  j  d g d t d t ƒ} | j | ƒ rP | t | ƒ j ƒ  d } n d } d j | j d ƒ d  ƒ } t | ƒ S(	   Ns   git version t   versiont   show_stdoutt   stdout_onlyi    t    t   .i   (   t   run_commandR!   t   Truet
   startswitht   lent   splitt   joint   parse_version(   R$   t   VERSION_PFXR+   (    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyt   get_git_versionP   s    c      
   C@  sc   d d d g } |  j  | d d
 d t d t d | ƒ} | j ƒ  } | j d	 ƒ r_ | 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,   R-   t   cwds   refs/heads/(   i   N(   R0   R!   R1   t   stripR2   R3   t   None(   t   clst   locationt   argst   outputt   ref(    (    s2   /tmp/pip-build-UPPWic/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,   R:   N(   t   endswithR   t   unpackt   pathR0   R!   (   R$   R>   R%   t   temp_dir(    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyRE   x   s    c   
   
   C@  sõ   |  j  d | g d | d t d t d d ƒ} i  } xc | j ƒ  j ƒ  D]O } y | j ƒ  \ } } Wn& t k
 rŠ t d j | ƒ ƒ ‚ n X| | | <qF 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-refR:   R,   R-   t   on_returncodet   ignores   unexpected show-ref line: {!r}s   refs/remotes/origin/{}s   refs/tags/{}N(
   R0   R!   R1   R;   t
   splitlinesR4   t
   ValueErrort   formatt   getR<   (
   R=   R&   R   R@   t   refst   lineR   RA   t
   branch_reft   tag_ref(    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyR#   …   s(    	
c         C@  s=   | j  d ƒ r t St | ƒ s# t S|  j | | ƒ r9 t St S(   s$  
        Return true if rev is a ref or is a commit that we don't have locally.

        Branches and tags are not considered in this method because they are
        assumed to be always available locally (which is a normal outcome of
        ``git clone`` and ``git fetch --tags``).
        s   refs/(   R2   R1   R   R!   t
   has_commit(   R=   R&   R   (    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyt   _should_fetch­   s    	c         C@  sì   | j  } | d k	 s t ‚ |  j | | ƒ \ } } | d k	 rg | j | ƒ } | rZ | n d | _ | St | ƒ s† t j d | ƒ n  |  j	 | | ƒ 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.t   fetchs   -qR:   R   t
   FETCH_HEADN(   t   arg_revR<   t   AssertionErrorR#   t   make_newt   branch_nameR   t   loggert   warningRU   R0   R   t   to_argst   get_revision(   R=   R&   R%   R(   R   R   t	   is_branch(    (    s2   /tmp/pip-build-UPPWic/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-UPPWic/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   -qR[   t   checkoutR:   s	   origin/{}s   -bs   --track(   t
   to_displayR\   t   infoR   R0   R   R   Ra   t   getattrR<   R"   R^   RB   RN   t   update_submodules(   R$   R&   R%   R(   t   rev_displayR[   t   cmd_argst   track_branch(    (    s2   /tmp/pip-build-UPPWic/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.urlR:   Rc   s   -q(   R0   R   R^   Rg   (   R$   R&   R%   R(   Ri   (    (    s2   /tmp/pip-build-UPPWic/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.0RV   s   -qs   --tagsR:   t   resets   --hard(   R8   R6   R0   Ra   R   R^   Rg   (   R$   R&   R%   R(   Ri   (    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyt   update)  s    c      
   C@  s«   |  j  d d d g d d d t d t d | ƒ} | j ƒ  } y | d	 } Wn t k
 rc t ‚ n Xx' | D] } | j d
 ƒ rk | } Pqk qk 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.
        Rl   s   --get-regexps   remote\..*\.urlR9   i   R,   R-   R:   i    s   remote.origin.url t    (   i   (	   R0   R!   R1   RL   t
   IndexErrorR
   R2   R4   R;   (   R=   R>   t   stdoutt   remotest   found_remotet   remoteR%   (    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyt   get_remote_url8  s"    
	
c         C@  sJ   y- |  j  d d d d | g d | d t ƒWn t k
 rA t SXt Sd S(   sU   
        Check if rev is a commit that is available in the local repository.
        s	   rev-parses   -qs   --verifys   sha^R:   t   log_failed_cmdN(   R0   R!   R   R1   (   R=   R>   R   (    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyRT   V  s    c         C@  sF   | d  k r d } n  |  j d | g d t d t d | ƒ} | j ƒ  S(   NR   s	   rev-parseR,   R-   R:   (   R<   R0   R!   R1   R;   (   R=   R>   R   t   current_rev(    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyR_   f  s    		c         C@  s…   |  j  d d g d t d t d | ƒj ƒ  } t j j | ƒ sW 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,   R-   R:   s   ..(
   R0   R!   R1   R;   t   osRH   t   isabsR5   t   abspathR   (   R=   R>   t   git_dirt	   repo_root(    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyt   get_subdirectoryr  s    !c         C@  s=  t  | ƒ \ } } } } } | j d ƒ r© | t | j d ƒ ƒ  } | t j | ƒ j d d ƒ j d ƒ } | 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   fileRC   s   \t   +i   s   ://s   file:s   git+s
   git+ssh://s   ssh://R.   (   t   urlsplitRF   R3   t   lstript   urllib_requestt   url2pathnamet   replacet   findt
   urlunsplitRY   t   superR   t   get_url_rev_and_auth(   R=   R%   t   schemet   netlocRH   t   queryt   fragmentt   initial_slashest   newpatht
   after_plusR   t	   user_pass(    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyR‰   „  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	   submoduleRo   s   --inits   --recursives   -qR:   (   Ry   RH   t   existsR5   R0   (   R=   R>   (    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyRg   ¦  s
    !c         C@  s¨   t  t |  ƒ j | ƒ } | r" | Sy7 |  j d d g d | d t d t d d d t ƒ} Wn3 t k
 r} t j d	 | ƒ d  St
 k
 rŽ d  SXt j j | j d
 ƒ ƒ S(   Ns	   rev-parses   --show-toplevelR:   R,   R-   RJ   t   raiseRw   sK   could not determine if %s is under git control because git is not availables   
(   Rˆ   R   t   get_repository_rootR0   R!   R1   R   R\   t   debugR<   R   Ry   RH   t   normpatht   rstrip(   R=   R>   t   loct   r(    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyR•   ¯  s$    	(   R   s   git+https	   git+httpss   git+sshs   git+gits   git+file(   R   R   N(   t   __name__t
   __module__Rb   t   dirnamet	   repo_namet   schemest   unset_environt   default_arg_revt   staticmethodR   R*   R8   t   classmethodRB   RE   R#   RU   Ra   R"   Rk   Rm   Ro   Rv   RT   R<   R_   R~   R‰   Rg   R•   (    (    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyR   /   s4   			(-			"	(.   t
   __future__R    t   loggingt   os.pathRy   t   ret   pip._vendor.packaging.versionR   R6   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›   R\   t   compileR   R   R   t   register(    (    (    s2   /tmp/pip-build-UPPWic/pip/pip/_internal/vcs/git.pyt   <module>   s0   "			ÿ ˜