3 ÝPf,- ã @ s´ d dl mZ d dlZd dlZd dlZd dlmZ d dlm Z d dl mZ d dl m Z d dlmZ d dlmZmZ d dlmZmZ ejZejZejeƒZG d d „ d eƒZejeƒ dS )é )Úabsolute_importN)Úsamefile)Ú BadCommand)Úparse)Úrequest)Údisplay_pathÚrmtree)ÚvcsÚVersionControlc sæ e Zd ZdZdZdZd7Zd8‡ fd d„ Zdd „ Zdd„ Z dd„ Z dd„ Zdd„ Zdd„ Z dd„ Zdd„ Zdd„ Zd9dd „Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd:d+d,„Zd-d.„ Zd/d0„ Z‡ fd1d2„Zd3d4„ Ze‡ fd5d6„ƒZ‡ ZS );ÚGitÚgitz.gitÚcloneúgit+httpú git+httpsúgit+sshúgit+gitúgit+fileNc s¶ |ršt |ƒ\}}}}}|jdƒrš|d t|jdƒƒ … } | tj|ƒjddƒjdƒ } t||| ||fƒ}|jdƒd }|d |… t||d … || ||fƒ }t t | ƒj|f|ž|Ž d S )NÚfileú/ú\ú+é )ÚurlsplitÚendswithÚlenÚlstripÚurllib_requestZurl2pathnameÚreplaceÚ urlunsplitÚfindÚsuperr Ú__init__)ÚselfÚurlÚargsÚkwargsÚschemeZnetlocÚpathZqueryZfragmentÚinitial_slashesÚnewpathZ after_plus)Ú __class__© ú/usr/lib/python3.6/git.pyr! s zGit.__init__c C sT d}| j dgdd�}|j|ƒr0|t|ƒd … }nd}dj|jdƒd d… ƒ}t|ƒS )Nzgit version ÚversionF)Úshow_stdoutÚ Ú.é )Úrun_commandÚ startswithr ÚjoinÚsplitÚ parse_version)r" ZVERSION_PFXr- r+ r+ r, Úget_git_version5 s zGit.get_git_versionc C sV t jddƒ}| j|ƒ z0|jdƒs*|d }| jdddd|gd|d � W d t|ƒ X d S )z@Export the Git repository at the url to the destination locationz-exportzpip-r zcheckout-indexz-az-fz--prefixF)r. ÚcwdN)ÚtempfileZmkdtempÚunpackr r2 r )r" ÚlocationZtemp_dirr+ r+ r, ÚexportB s z Git.exportc C sL | j ||ƒ}d| }||kr&|| gS ||kr8|| gS tjd|ƒ |S dS )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 zGit.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 zGit.check_versionc C s8 | j dd|g|d� | j ddg| |d� | j|ƒ d S )NÚconfigzremote.origin.url)r8 Úcheckoutz-q)r2 Úupdate_submodules)r" rA r# rB r+ r+ r, Úswitchl s z Git.switchc C st | j ƒ tdƒkr&| jdddg|d� n| jddg|d� |rN| j|d ||ƒ}| jdddg| |d� | j|ƒ d S ) Nz1.9.0Zfetchz-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 dg}d}| j||||ƒržtjd||t|ƒƒ | jdd||gƒ |r”| j|||ƒ}| j||ƒs”| jddg| |d� | j|ƒ d S ) Nz (to %s)z origin/masterr/ zCloning %s%s to %sr z-qrG )r8 ) Úget_url_revZcheck_destinationr> Úinfor r2 rC rE rH )r" rA r# r@ rB Zrev_displayr+ r+ r, Úobtain‚ s" z Git.obtainc C sZ | j dddgd|d�}|jƒ }|d }x|D ]}|jdƒr,|}P q,W |jdƒd }|jƒ S ) z+Return URL of the first remote encountered.rF z--get-regexpzremote\..*\.urlF)r. r8 r zremote.origin.url ú r )r2 Ú splitlinesr3 r5 Ústrip)r" r; ZremotesZfound_remoteZremoter# r+ r+ r, Úget_url› s zGit.get_urlc C s | j ddgd|d�}|jƒ S )Nz rev-parseZHEADF)r. r8 )r2 rQ )r" r; Úcurrent_revr+ r+ r, rD © s zGit.get_revisionr/ c c s† | j d|gd|d�}xl|jdƒD ]^}|jdƒ}|s4q y|jddƒ\}}W n" tk rj td|›�ƒ‚Y nX |jƒ |jƒ fV q W d S ) z4Yields tuples of (commit, ref) for branches and tagszshow-refF)r. r8 Ú ú rO r zunexpected show-ref line: N)r2 r5 ÚrstripÚ ValueErrorrQ )r" r; ÚpatternÚoutputÚlineÚcommitÚrefr+ r+ r, Ú get_full_refs® s zGit.get_full_refsc C s |j dƒS )Nz refs/remotes/)r3 )r" r\ r+ r+ r, Ú is_ref_remote¾ s zGit.is_ref_remotec C s |j dƒS )Nzrefs/heads/)r3 )r" r\ r+ r+ r, Ú is_ref_branchÁ s zGit.is_ref_branchc C s |j dƒS )Nz refs/tags/)r3 )r" r\ r+ r+ r, Ú is_ref_tagÄ s zGit.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 zGit.is_ref_commitc C s | j |ƒS )N)r= )r" r; r+ r+ r, Úget_refsÐ s zGit.get_refsc C sˆ i }x~| j ||ƒD ]n\}}d}| j|ƒr:|tdƒd… }n6| j|ƒrV|tdƒd… }n| j|ƒrp|tdƒd… }|dk r|||<