ó
<¾^Yc           @@  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 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 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(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyR       s    
#c         C@  sl   d } |  j  d g d t ƒ} | j | ƒ r@ | t | ƒ } n d } d j | j d ƒ d  ƒ } t | ƒ S(   Ns   git version t   versiont   show_stdoutt    t   .i   (   t   run_commandt   Falset
   startswithR   t   joint   splitt   parse_version(   R   t   VERSION_PFXR&   (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   get_git_version5   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   --prefixR'   t   cwdN(   t   tempfilet   mkdtempt   unpackR   R*   R+   R   (   R   t   locationt   temp_dir(    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   exportB   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(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   check_rev_optionsO   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_revisionR,   (   R   R=   R>   (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   check_versionc   s    c         C@  sJ   |  j  d d | g d | ƒ|  j  d d g | d | ƒ|  j | ƒ d  S(   Nt   configs   remote.origin.urlR2   t   checkouts   -q(   R*   t   update_submodules(   R   R=   R   R>   (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   switchl   s    c         C@  s£   |  j  ƒ  t d ƒ k r7 |  j d d d g d | ƒn |  j d d g d | ƒ| rr |  j | d | | ƒ } n  |  j d d d g | d | ƒ|  j | ƒ d  S(	   Ns   1.9.0t   fetchs   -qs   --tagsR2   i    t   resets   --hard(   R1   R/   R*   RA   RF   (   R   R=   R>   (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   updater   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/masterR(   s   Cloning %s%s to %sR   s   -qRE   R2   (	   t   get_url_revt   check_destinationR:   t   infoR   R*   RA   RC   RF   (   R   R=   R   R<   R>   t   rev_display(    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   obtain‚   s"    		c         C@  s   |  j  d d d g d t d | ƒ} | j ƒ  } | d } x' | D] } | j d ƒ rA | } PqA qA W| j d ƒ d	 } | j ƒ  S(
   s+   Return URL of the first remote encountered.RD   s   --get-regexps   remote\..*\.urlR'   R2   i    s   remote.origin.url t    i   (   R*   R+   t
   splitlinesR,   R.   t   strip(   R   R6   t   remotest   found_remotet   remoteR   (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   get_url›   s    
c         C@  s+   |  j  d d g d t d | ƒ} | j ƒ  S(   Ns	   rev-parset   HEADR'   R2   (   R*   R+   RR   (   R   R6   t   current_rev(    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyRB   ©   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'   R2   RP   i   N(   R*   R+   RR   RQ   R.   (   R   R6   t   outputt   linet   committ   ref(    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   get_full_refs®   s
    c         C@  s   | j  d ƒ S(   Ns   refs/remotes/(   R,   (   R   R\   (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   is_ref_remote¶   s    c         C@  s   | j  d ƒ S(   Ns   refs/heads/(   R,   (   R   R\   (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   is_ref_branch¹   s    c         C@  s   | j  d ƒ S(   Ns
   refs/tags/(   R,   (   R   R\   (    (    s(   /tmp/pip-build-YOdFBd/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   anyR^   R_   R`   (   R   R\   (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   is_ref_commit¿   s    c         C@  s   |  j  | ƒ S(   N(   R9   (   R   R6   (    (    s(   /tmp/pip-build-YOdFBd/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(   R]   t   NoneR^   R   R_   R`   (   R   R6   t   rvR[   R\   t   ref_name(    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyR9   Ë   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'   R2   s   ..s   setup.pysG   Could not find setup.py for directory %s (tried all parent directories)N(   R*   R+   RR   t   osR    t   isabsR-   t   existst   dirnameR:   R;   Rd   R   t   relpath(   R   R6   t   git_dirt   root_dirt   orig_locationt   last_location(    (    s(   /tmp/pip-build-YOdFBd/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=(   RV   t   lowerR,   t   egg_nameR.   Rd   RB   Rp   (   R   t   distR6   t   repot   egg_project_nameRX   t   reqt   subdirectory(    (    s(   /tmp/pip-build-YOdFBd/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://R(   (   R   t   AssertionErrorR   R   R	   RK   (   R   R   R<   (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyRK     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	   submoduleRJ   s   --inits   --recursives   -qR2   (   Rg   R    Ri   R-   R*   (   R   R6   (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyRF     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-parseR2   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   R:   t   debug(   t   clsR6   t   r(    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyR~     s    			(   s   gits   git+https	   git+httpss   git+sshs   git+gits   git+fileN(   t   __name__t
   __module__t   nameRj   t	   repo_namet   schemesRd   R   R1   R8   RA   RC   RG   RJ   RO   RV   RB   R]   R^   R_   R`   Rb   Rc   R9   Rp   Ry   RK   RF   t   classmethodR~   (    (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyR	      s4   																						(   t
   __future__R    t   loggingR3   t   os.pathRg   t
   pip.compatR   t   pip.exceptionsR   t   pip._vendor.six.moves.urllibR   t   urllib_parseR   R   t   pip._vendor.packaging.versionR/   t	   pip.utilsR   R   t   pip.vcsR   R   R   R   t	   getLoggerRƒ   R:   R	   t   register(    (    (    s(   /tmp/pip-build-YOdFBd/pip/pip/vcs/git.pyt   <module>   s    		ÿ 