
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
ÝPf,-  ã               @   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G d	d
„ d
eƒZejeƒ dS )é    )Úabsolute_importN)Úsamefile)Ú
BadCommand)Úparse)Úrequest)Údisplay_pathÚrmtree)ÚvcsÚVersionControlc                   sæ   e Zd ZdZdZdZd7Zd8‡ fd
d„	Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd9dd „Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd:d+d,„Zd-d.„ Zd/d0„ Z‡ fd1d2„Zd3d4„ Ze‡ fd5d6„ƒZ‡  ZS );ÚGitÚgitz.gitÚcloneúgit+httpú	git+httpsúgit+sshúgit+gitúgit+fileNc                s¶   |ršt |ƒ\}}}}}|jdƒrš|d t|jdƒƒ … }	|	tj|ƒjddƒjdƒ }
t|||
||fƒ}|jdƒd }|d |… t||d … ||
||fƒ }t	t
| ƒj|f|ž|Ž d S )NÚfileú/ú\ú+é   )ÚurlsplitÚendswithÚlenÚlstripÚurllib_requestZurl2pathnameÚreplaceÚ
urlunsplitÚfindÚsuperr   Ú__init__)ÚselfÚurlÚargsÚkwargsÚschemeZnetlocÚpathZqueryZfragmentÚinitial_slashesÚnewpathZ
after_plus)Ú	__class__© ú/usr/lib/python3.6/git.pyr!       s    

zGit.__init__c             C   sT   d}| j dgdd�}|j|ƒr0|t|ƒd … }nd}dj|jdƒd d… ƒ}t|ƒS )Nzgit version ÚversionF)Úshow_stdoutÚ Ú.é   )Úrun_commandÚ
startswithr   ÚjoinÚsplitÚparse_version)r"   ZVERSION_PFXr-   r+   r+   r,   Úget_git_version5   s    
zGit.get_git_versionc             C   sV   t jddƒ}| j|ƒ z0|jdƒs*|d }| jdddd|gd|d	� W d
t|ƒ X d
S )z@Export the Git repository at the url to the destination locationz-exportzpip-r   zcheckout-indexz-az-fz--prefixF)r.   ÚcwdN)ÚtempfileZmkdtempÚunpackr   r2   r   )r"   ÚlocationZtemp_dirr+   r+   r,   ÚexportB   s    

z
Git.exportc             C   sL   | j ||ƒ}d| }||kr&|| gS ||kr8|| gS tjd|ƒ |S dS )z¶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.
        z	origin/%sz5Could not find a tag or branch '%s', assuming commit.N)Úget_short_refsÚloggerÚwarning)r"   ÚrevÚdestÚrev_optionsZ	revisionsZ
origin_revr+   r+   r,   Úcheck_rev_optionsO   s    

zGit.check_rev_optionsc             C   s   | j |ƒj|d ƒS )a
  
        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.
        r   )Úget_revisionr3   )r"   rA   rB   r+   r+   r,   Úcheck_versionc   s    zGit.check_versionc             C   s8   | j dd|g|d� | j ddg| |d� | j|ƒ d S )NÚconfigzremote.origin.url)r8   Úcheckoutz-q)r2   Úupdate_submodules)r"   rA   r#   rB   r+   r+   r,   Úswitchl   s    z
Git.switchc             C   st   | j ƒ tdƒkr&| jdddg|d� n| jddg|d� |rN| j|d ||ƒ}| jdddg| |d� | j|ƒ d S )	Nz1.9.0Zfetchz-qz--tags)r8   r   Úresetz--hard)r7   r6   r2   rC   rH   )r"   rA   rB   r+   r+   r,   Úupdater   s    z
Git.updatec             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� | j|ƒ d S )	Nz (to %s)zorigin/masterr/   zCloning %s%s to %sr   z-qrG   )r8   )	Úget_url_revZcheck_destinationr>   Úinfor   r2   rC   rE   rH   )r"   rA   r#   r@   rB   Zrev_displayr+   r+   r,   Úobtain‚   s"    

z
Git.obtainc             C   sZ   | j dddgd|d�}|jƒ }|d }x|D ]}|jdƒr,|}P q,W |jdƒd	 }|jƒ S )
z+Return URL of the first remote encountered.rF   z--get-regexpzremote\..*\.urlF)r.   r8   r   zremote.origin.url ú r   )r2   Ú
splitlinesr3   r5   Ústrip)r"   r;   ZremotesZfound_remoteZremoter#   r+   r+   r,   Úget_url›   s    


zGit.get_urlc             C   s   | j ddgd|d�}|jƒ S )Nz	rev-parseZHEADF)r.   r8   )r2   rQ   )r"   r;   Úcurrent_revr+   r+   r,   rD   ©   s    zGit.get_revisionr/   c             c   s†   | j d|gd|d�}xl|jdƒD ]^}|jdƒ}|s4q y|jddƒ\}}W n" tk
rj   td|›�ƒ‚Y nX |jƒ |jƒ fV  q W d	S )
z4Yields tuples of (commit, ref) for branches and tagszshow-refF)r.   r8   Ú
úrO   r   zunexpected show-ref line: N)r2   r5   ÚrstripÚ
ValueErrorrQ   )r"   r;   ÚpatternÚoutputÚlineÚcommitÚrefr+   r+   r,   Úget_full_refs®   s    


zGit.get_full_refsc             C   s
   |j dƒS )Nzrefs/remotes/)r3   )r"   r\   r+   r+   r,   Úis_ref_remote¾   s    zGit.is_ref_remotec             C   s
   |j dƒS )Nzrefs/heads/)r3   )r"   r\   r+   r+   r,   Úis_ref_branchÁ   s    zGit.is_ref_branchc             C   s
   |j dƒS )Nz
refs/tags/)r3   )r"   r\   r+   r+   r,   Ú
is_ref_tagÄ   s    zGit.is_ref_tagc             C   s"   t | j|ƒ| j|ƒ| j|ƒfƒ S )z0A ref is a commit sha if it is not anything else)Úanyr^   r_   r`   )r"   r\   r+   r+   r,   Úis_ref_commitÇ   s    zGit.is_ref_commitc             C   s
   | j |ƒS )N)r=   )r"   r;   r+   r+   r,   Úget_refsÐ   s    zGit.get_refsc             C   sˆ   i }x~| j ||ƒD ]n\}}d}| j|ƒr:|tdƒd… }n6| j|ƒrV|tdƒd… }n| j|ƒrp|tdƒd… }|dk	r|||< qW |S )z=Return map of named refs (branches or tags) to commit hashes.Nzrefs/remotes/zrefs/heads/z
refs/tags/)r]   r^   r   r_   r`   )r"   r;   rX   Úrvr[   r\   Zref_namer+   r+   r,   r=   Ó   s    


zGit.get_short_refsc             C   s¤   | j ddgd|d�jƒ }tjj|ƒs2tjj||ƒ}tjj|dƒ}|}xBtjjtjj|dƒƒs†|}tjj|ƒ}||krFtj	d|ƒ dS qFW t
||ƒr–dS tjj||ƒS )	z:Return the relative path of setup.py to the git repo root.z	rev-parsez	--git-dirF)r.   r8   z..zsetup.pyzGCould not find setup.py for directory %s (tried all parent directories)N)r2   rQ   Úosr'   Úisabsr4   ÚexistsÚdirnamer>   r?   r   Úrelpath)r"   r;   Zgit_dirZroot_dirZorig_locationZlast_locationr+   r+   r,   Ú_get_subdirectoryâ   s"    

zGit._get_subdirectoryc             C   sr   | j |ƒ}|jƒ jdƒs d| }|jƒ jddƒd }|s<d S | j|ƒ}d|||f }| j|ƒ}|rn|d| 7 }|S )Nzgit:zgit+ú-r   r   z%s@%s#egg=%sz&subdirectory=)rR   Úlowerr3   Zegg_namer5   rD   rj   )r"   Zdistr;   ZrepoZegg_project_namerS   ZreqZsubdirectoryr+   r+   r,   Úget_src_requirementý   s    


zGit.get_src_requirementc                sb   d| j krHd| j kst‚| j jddƒ| _ tt| ƒjƒ \}}|jddƒ}ntt| ƒjƒ \}}||fS )a;  
        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.
        z://zfile:zgit+z
git+ssh://zssh://r/   )r#   ÚAssertionErrorr   r    r   rL   )r"   r#   r@   )r*   r+   r,   rL     s    
zGit.get_url_revc             C   s6   t jjt jj|dƒƒsd S | jdddddg|d� d S )Nz.gitmodulesZ	submodulerK   z--initz--recursivez-q)r8   )re   r'   rg   r4   r2   )r"   r;   r+   r+   r,   rH     s
    zGit.update_submodulesc                sV   t t| ƒj|ƒrdS y| ƒ jdg|ddd�}| S  tk
rP   tjd|ƒ dS X d S )NTz	rev-parseFÚignore)r8   r.   Zon_returncodezKcould not determine if %s is under git control because git is not available)r    r   Úcontrols_locationr2   r   r>   Údebug)Úclsr;   Úr)r*   r+   r,   rp   $  s    
zGit.controls_location)r   r   r   r   r   r   )N)r/   )r/   )Ú__name__Ú
__module__Ú__qualname__Únamerh   Z	repo_nameZschemesr!   r7   r<   rC   rE   rI   rK   rN   rR   rD   r]   r^   r_   r`   rb   rc   r=   rj   rm   rL   rH   Úclassmethodrp   Ú__classcell__r+   r+   )r*   r,   r      s4   	
	
r   )Z
__future__r   Zloggingr9   Zos.pathre   Z
pip.compatr   Zpip.exceptionsr   Zpip._vendor.six.moves.urllibr   Zurllib_parser   r   Zpip._vendor.packaging.versionr6   Z	pip.utilsr   r   Zpip.vcsr	   r
   r   r   Z	getLoggerrt   r>   r   Úregisterr+   r+   r+   r,   Ú<module>   s"   
  