ó
b]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 d  d l m Z m Z d  d l m Z d  d	 l m Z m Z m Z 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   samefile(   t   display_patht   redact_password_from_url(   t   TempDirectory(   t   RemoteNotFoundErrort   VersionControlt   vcss   ^[a-fA-F0-9]{40}$c         C@  s   t  t j |  ƒ ƒ S(   N(   t   boolt
   HASH_REGEXt   match(   t   sha(    (    s4   lib/python2.7/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
 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(    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyt   get_base_rev_args-   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_commandt   Falset
   startswitht   lent   splitt   joint   parse_version(   t   selft   VERSION_PFXR   (    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyt   get_git_version1   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   R   t   None(   t   clst   locationt   argst   outputt   ref(    (    s4   lib/python2.7/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   exportt   urls   checkout-indexs   -as   -fs   --prefixR   R'   N(   t   endswithR   t   unpackt   pathR   R   (   R#   R+   R3   t   temp_dir(    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyR2   S   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-refR'   R   t   on_returncodet   ignores   unexpected show-ref line: {!r}s   refs/remotes/origin/{}s   refs/tags/{}N(
   R   R   R(   t
   splitlinesR    t
   ValueErrort   formatt   getR)   t   True(
   R*   t   destR   R-   t   refst   lineR   R.   t
   branch_reft   tag_ref(    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyt   get_revision_sha_   s     
c         C@  sÕ   | j  } |  j | | ƒ \ } } | d k	 rU | j | ƒ } | rH | n d | _ | St | ƒ st t j d | ƒ n  | j d ƒ s‡ | S|  j	 d d | g | 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   -qR'   R   t
   FETCH_HEADN(   t   arg_revRD   R)   t   make_newt   branch_nameR   t   loggert   warningR   R   t   to_argst   get_revision(   R*   R?   R3   t   rev_optionsR   R   t	   is_branch(    (    s4   lib/python2.7/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   RM   (   R*   R?   t   name(    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyt   is_commit_id_equalª   s    	c         C@  s*  | j  ƒ  } t j d t | ƒ | t | ƒ ƒ |  j d d | | g ƒ | j r|  j | | | ƒ } t | d d  ƒ } | d  k rÇ |  j
 | | j ƒ sd d g | 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   -qRI   t   checkoutR'   s	   origin/{}s   -bs   --track(   t
   to_displayRJ   t   infoR   R   R   R   RP   t   getattrR)   RR   RL   R/   R<   t   update_submodules(   R#   R?   R3   RN   t   rev_displayRI   t   cmd_argst   track_branch(    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyt	   fetch_new¹   s"    	c         C@  sV   |  j  d d | g d | ƒd d g | j ƒ  } |  j  | d | ƒ|  j | ƒ d  S(   Nt   configs   remote.origin.urlR'   RS   s   -q(   R   RL   RW   (   R#   R?   R3   RN   RY   (    (    s4   lib/python2.7/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 | | | ƒ } d d d g | j ƒ  } |  j | d | ƒ|  j | ƒ d  S(   Ns   1.9.0RE   s   -qs   --tagsR'   t   resets   --hard(   R%   R"   R   RP   RL   RW   (   R#   R?   R3   RN   RY   (    (    s4   lib/python2.7/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.
        R\   s   --get-regexps   remote\..*\.urlR&   i   R   R'   i    s   remote.origin.url t    (   i   (   R   R   R:   t
   IndexErrorR   R   R    R(   (   R*   R+   t   stdoutt   remotest   found_remotet   remoteR3   (    (    s4   lib/python2.7/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   R'   (   R)   R   R   R(   (   R*   R+   R   t   current_rev(    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyRM     s
    	c         C@  sò   |  j  d d g d t d | ƒj ƒ  } t j j | ƒ sQ t j j | | ƒ } n  t j j | d ƒ } | } x] t j j t j j | d ƒ ƒ sË | } t j j | ƒ } | | k ro t	 j
 d | ƒ d  Sqo Wt | | ƒ rß d  St j j | | ƒ S(   Ns	   rev-parses	   --git-dirR   R'   s   ..s   setup.pysG   Could not find setup.py for directory %s (tried all parent directories)(   R   R   R(   t   osR6   t   isabsR!   t   existst   dirnameRJ   RK   R)   R   t   relpath(   R*   R+   t   git_dirt   root_dirt   orig_locationt   last_location(    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyt   get_subdirectory  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   fileR0   s   \t   +i   s   ://s   file:s   git+s
   git+ssh://s   ssh://R   (   t   urlsplitR4   R   t   lstript   urllib_requestt   url2pathnamet   replacet
   urlunsplitt   findt   AssertionErrort   superR   t   get_url_rev_and_auth(   R*   R3   t   schemet   netlocR6   t   queryt   fragmentt   initial_slashest   newpatht
   after_plusR   t	   user_pass(    (    s4   lib/python2.7/site-packages/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	   submoduleR_   s   --inits   --recursives   -qR'   (   Rh   R6   Rj   R!   R   (   R*   R+   (    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyRW   M  s
    !c         C@  sr   t  t |  ƒ j | ƒ r t Sy- |  j d g d | d t d d ƒ} | SWn" t k
 rm t j d | ƒ t SXd  S(   Ns	   rev-parseR'   R   R8   R9   sK   could not determine if %s is under git control because git is not available(	   R|   R   t   controls_locationR>   R   R   R   RJ   t   debug(   R*   R+   t   r(    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyR‡   V  s    			(   R   s   git+https	   git+httpss   git+sshs   git+gits   git+file(   R   R   N(   t   __name__t
   __module__RQ   Rk   t	   repo_namet   schemest   unset_environt   default_arg_revt   staticmethodR   R%   t   classmethodR/   R2   RD   RP   RR   R[   R]   R_   Rf   R)   RM   Rq   R}   RW   R‡   (    (    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyR   !   s.   		#(			"	($   t
   __future__R    t   loggingt   os.pathRh   t   ret   pip._vendor.packaging.versionR   R"   t   pip._vendor.six.moves.urllibt   urllib_parseR   Rv   t   pip._internal.exceptionsR   t   pip._internal.utils.compatR   t   pip._internal.utils.miscR   R   t   pip._internal.utils.temp_dirR   t    pip._internal.vcs.versioncontrolR   R	   R
   Rt   Ry   t	   getLoggerRŠ   RJ   t   compileR   R   R   t   register(    (    (    s4   lib/python2.7/site-packages/pip/_internal/vcs/git.pyt   <module>   s&   			ÿ F