σ
^κWc           @@  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 m Z e j Z e j Z e j e  Z d	 e f d
     YZ e j e  d S(   i    (   t   absolute_importN(   t   samefile(   t
   BadCommand(   t   parse(   t   request(   t   display_patht   rmtree(   t   vcst   VersionControlt   Gitc           B@  sζ   e  Z d  Z d Z d Z d Z d d  Z d	   Z d
   Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d    Z RS(   t   gits   .gitt   clones   git+https	   git+httpss   git+sshs   git+gits   git+filec         O@  sν   | rΝ t  |  \ } } } } } | j d  rΝ | t | j d    }	 |	 t j |  j d d  j d  }
 t | | |
 | | f  } | j d  d } | |  t | | | |
 | | f  } qΝ n  t	 t
 |   j | | |  d  S(   Nt   filet   /s   \t   +i   (   t   urlsplitt   endswitht   lent   lstript   urllib_requestt   url2pathnamet   replacet
   urlunsplitt   findt   superR	   t   __init__(   t   selft   urlt   argst   kwargst   schemet   netloct   patht   queryt   fragmentt   initial_slashest   newpatht
   after_plus(    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyR      s    
#c         C@  sy   t  j d d  } |  j |  zH | j d  s> | d } n  |  j d d d d | g d t d	 | Wd
 t |  Xd
 S(   s@   Export the Git repository at the url to the destination locations   -exports   pip-R   s   checkout-indexs   -as   -fs   --prefixt   show_stdoutt   cwdN(   t   tempfilet   mkdtempt   unpackR   t   run_commandt   FalseR   (   R   t   locationt   temp_dir(    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   export4   s    c         C@  s_   |  j  |  } d | } | | k r0 | | g S| | k rG | | g St j d |  | Sd S(   sΆ   Check the revision options before checkout to compensate that tags
        and branches may need origin/ as a prefix.
        Returns the SHA1 of the branch or tag if found.
        s	   origin/%ss5   Could not find a tag or branch '%s', assuming commit.N(   t   get_short_refst   loggert   warning(   R   t   revt   destt   rev_optionst	   revisionst
   origin_rev(    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   check_rev_optionsA   s    

c         C@  s   |  j  |  j | d  S(   s
  
        Compare the current sha to the ref. ref may be a branch or tag name,
        but current rev will always point to a sha. This means that a branch
        or tag will never compare as True. So this ultimately only matches
        against exact shas.
        i    (   t   get_revisiont
   startswith(   R   R4   R5   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   check_versionU   s    c         C@  sJ   |  j  d d | g d | |  j  d d g | d | |  j |  d  S(   Nt   configs   remote.origin.urlR'   t   checkouts   -q(   R+   t   update_submodules(   R   R4   R   R5   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   switch^   s    c         C@  sl   |  j  d d g d | | r; |  j | d | |  } n  |  j  d d d g | d | |  j |  d  S(   Nt   fetchs   -qR'   i    t   resets   --hard(   R+   R8   R>   (   R   R4   R5   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   updated   s     c         C@  sξ   |  j    \ } } | r. | g } d | } n d g } d } |  j | | | |  rκ t j d | | t |   |  j d d | | g  | rΪ |  j | | |  } |  j | |  sΪ |  j d d g | d | qΪ n  |  j |  n  d  S(	   Ns    (to %s)s   origin/mastert    s   Cloning %s%s to %sR   s   -qR=   R'   (	   t   get_url_revt   check_destinationR1   t   infoR   R+   R8   R;   R>   (   R   R4   R   R3   R5   t   rev_display(    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   obtainp   s"    		c         C@  sQ   |  j  d d d g d t d | } | j   d } | j d  d } | j   S(	   s+   Return URL of the first remote encountered.R<   s   --get-regexps   remote\..*\.urlR&   R'   i    t    i   (   R+   R,   t
   splitlinest   splitt   strip(   R   R-   t   remotest   first_remoteR   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   get_url   s    c         C@  s+   |  j  d d g d t d | } | j   S(   Ns	   rev-parset   HEADR&   R'   (   R+   R,   RL   (   R   R-   t   current_rev(    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyR9      s    c         c@  sn   |  j  d g d t d | } xI | j   j   D]5 } | j d d  \ } } | j   | j   f Vq1 Wd S(   s4   Yields tuples of (commit, ref) for branches and tagss   show-refR&   R'   RI   i   N(   R+   R,   RL   RJ   RK   (   R   R-   t   outputt   linet   committ   ref(    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   get_full_refs   s
    c         C@  s   | j  d  S(   Ns   refs/remotes/(   R:   (   R   RU   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   is_ref_remote   s    c         C@  s   | j  d  S(   Ns   refs/heads/(   R:   (   R   RU   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   is_ref_branch’   s    c         C@  s   | j  d  S(   Ns
   refs/tags/(   R:   (   R   RU   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt
   is_ref_tag₯   s    c         C@  s/   t  |  j |  |  j |  |  j |  f  S(   s0   A ref is a commit sha if it is not anything else(   t   anyRW   RX   RY   (   R   RU   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   is_ref_commit¨   s    c         C@  s   |  j  |  S(   N(   R0   (   R   R-   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   get_refs±   s    c         C@  s―   i  } x’ |  j  |  D] \ } } d } |  j |  rJ | t d  } nD |  j |  rl | t d  } n" |  j |  r | t d  } n  | d k	 r | | | <q q W| S(   s=   Return map of named refs (branches or tags) to commit hashes.s   refs/remotes/s   refs/heads/s
   refs/tags/N(   RV   t   NoneRW   R   RX   RY   (   R   R-   t   rvRT   RU   t   ref_name(    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyR0   ΄   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(	   s:   Return the relative path of setup.py to the git repo root.s	   rev-parses	   --git-dirR&   R'   s   ..s   setup.pysG   Could not find setup.py for directory %s (tried all parent directories)N(   R+   R,   RL   t   osR    t   isabst   joint   existst   dirnameR1   R2   R]   R   t   relpath(   R   R-   t   git_dirt   root_dirt   orig_locationt   last_location(    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   _get_subdirectoryΓ   s"    $c         C@  s£   |  j  |  } | j   j d  s1 d | } n  | j   j d d  d } | sW d  S|  j |  } d | | | f } |  j |  } | r | d | 7} n  | S(   Ns   git:s   git+t   -i   i    s   %s@%s#egg=%ss   &subdirectory=(   RO   t   lowerR:   t   egg_nameRK   R]   R9   Rj   (   R   t   distR-   t   repot   egg_project_nameRQ   t   reqt   subdirectory(    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   get_src_requirementή   s    c         C@  s   d |  j  k rl d |  j  k s$ t  |  j  j d d  |  _  t t |   j   \ } } | j d d  } n t t |   j   \ } } | | f S(   s;  
        Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'.
        That's required because although they use SSH they sometimes doesn'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.
        s   ://s   file:s   git+s
   git+ssh://s   ssh://RC   (   R   t   AssertionErrorR   R   R	   RD   (   R   R   R3   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyRD   μ   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	   submoduleRB   s   --inits   --recursives   -qR'   (   R`   R    Rc   Rb   R+   (   R   R-   (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyR>   ύ   s
    !c         C@  su   t  t |   j |  r t Sy0 |    j d g d | d t d d } | SWn" t k
 rp t j d |  t SXd  S(   Ns	   rev-parseR'   R&   t   on_returncodet   ignoresK   could not determine if %s is under git control because git is not available(	   R   R	   t   controls_locationt   TrueR+   R,   R   R1   t   debug(   t   clsR-   t   r(    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyRx     s    			(   s   gits   git+https	   git+httpss   git+sshs   git+gits   git+fileN(   t   __name__t
   __module__t   nameRd   t	   repo_namet   schemesR]   R   R/   R8   R;   R?   RB   RH   RO   R9   RV   RW   RX   RY   R[   R\   R0   Rj   Rs   RD   R>   t   classmethodRx   (    (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyR	      s2   																						(   t
   __future__R    t   loggingR(   t   os.pathR`   t
   pip.compatR   t   pip.exceptionsR   t   pip._vendor.six.moves.urllibR   t   urllib_parseR   R   t	   pip.utilsR   R   t   pip.vcsR   R   R   R   t	   getLoggerR}   R1   R	   t   register(    (    (    s\   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/vcs/git.pyt   <module>   s   		ώ