3 ÝPf,-ã@s´ddlmZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Zddlm ZddlmZmZddlmZmZe jZe jZejeƒZGd d „d eƒZejeƒdS) é)Úabsolute_importN)Úsamefile)Ú BadCommand)Úparse)Úrequest)Ú display_pathÚrmtree)ÚvcsÚVersionControlcsæeZdZdZdZdZd7Zd8‡fd d „ Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„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š|dt|jdƒƒ …} | tj|ƒjddƒjdƒ} t||| ||fƒ}|jdƒd} |d| …t|| d…|| ||fƒ}t t |ƒj |f|ž|ŽdS)NÚfileú/ú\ú+é) ÚurlsplitÚendswithÚlenÚlstripÚurllib_requestZ url2pathnameÚreplaceÚ urlunsplitÚfindÚsuperr Ú__init__) ÚselfÚurlÚargsÚkwargsÚschemeZnetlocÚpathZqueryZfragmentÚinitial_slashesÚnewpathZ after_plus)Ú __class__©ú/usr/lib/python3.6/git.pyr! s   z Git.__init__cCsTd}|jdgdd�}|j|ƒr0|t|ƒd…}nd}dj|jdƒdd…ƒ}t|ƒS)Nz git version ÚversionF)Ú show_stdoutÚÚ.é)Ú run_commandÚ startswithrÚjoinÚsplitÚ parse_version)r"Z VERSION_PFXr-r+r+r,Úget_git_version5s zGit.get_git_versionc CsVtjddƒ}|j|ƒz0|jdƒs*|d}|jdddd|gd|d �Wd t|ƒXd S) z@Export the Git repository at the url to the destination locationz-exportzpip-rzcheckout-indexz-az-fz--prefixF)r.ÚcwdN)ÚtempfileZmkdtempÚunpackrr2r)r"ÚlocationZtemp_dirr+r+r,ÚexportBs    z Git.exportcCsL|j||ƒ}d|}||kr&||gS||kr8||gStjd|ƒ|SdS)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_optionsOs   zGit.check_rev_optionscCs|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"rArBr+r+r,Ú check_versioncszGit.check_versioncCs8|jdd|g|d�|jddg||d�|j|ƒdS)NÚconfigzremote.origin.url)r8Úcheckoutz-q)r2Úupdate_submodules)r"rAr#rBr+r+r,Úswitchlsz Git.switchcCst|jƒtdƒkr&|jdddg|d�n|jddg|d�|rN|j|d||ƒ}|jdddg||d�|j|ƒdS) Nz1.9.0Zfetchz-qz--tags)r8rÚresetz--hard)r7r6r2rCrH)r"rArBr+r+r,Úupdatersz Git.updatecCs¢|jƒ\}}|r |g}d|}n dg}d}|j||||ƒržtjd||t|ƒƒ|jdd||gƒ|r”|j|||ƒ}|j||ƒs”|jddg||d�|j|ƒdS) Nz (to %s)z origin/masterr/zCloning %s%s to %sr z-qrG)r8) Ú get_url_revZcheck_destinationr>Úinforr2rCrErH)r"rAr#r@rBZ rev_displayr+r+r,Úobtain‚s"    z Git.obtaincCsZ|jdddgd|d�}|jƒ}|d}x|D]}|jdƒr,|}Pq,W|jdƒd }|jƒS) z+Return URL of the first remote encountered.rFz --get-regexpzremote\..*\.urlF)r.r8rzremote.origin.url ú r)r2Ú splitlinesr3r5Ústrip)r"r;ZremotesZ found_remoteZremoter#r+r+r,Úget_url›s   z Git.get_urlcCs|jddgd|d�}|jƒS)Nz rev-parseZHEADF)r.r8)r2rQ)r"r;Ú current_revr+r+r,rD©szGit.get_revisionr/c cs†|jd|gd|d�}xl|jdƒD]^}|jdƒ}|s4q y|jddƒ\}}Wn"tk rjtd|›�ƒ‚YnX|jƒ|jƒfVq Wd S) z4Yields tuples of (commit, ref) for branches and tagszshow-refF)r.r8Ú ú rOrzunexpected show-ref line: N)r2r5ÚrstripÚ ValueErrorrQ)r"r;ÚpatternÚoutputÚlineÚcommitÚrefr+r+r,Ú get_full_refs®s   zGit.get_full_refscCs |jdƒS)Nz refs/remotes/)r3)r"r\r+r+r,Ú is_ref_remote¾szGit.is_ref_remotecCs |jdƒS)Nz refs/heads/)r3)r"r\r+r+r,Ú is_ref_branchÁszGit.is_ref_branchcCs |jdƒS)Nz refs/tags/)r3)r"r\r+r+r,Ú is_ref_tagÄszGit.is_ref_tagcCs"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ÇszGit.is_ref_commitcCs |j|ƒS)N)r=)r"r;r+r+r,Úget_refsÐsz Git.get_refscCsˆi}x~|j||ƒD]n\}}d}|j|ƒr:|tdƒd…}n6|j|ƒrV|tdƒd…}n|j|ƒrp|tdƒd…}|dk r|||<qW|S)z=Return map of named refs (branches or tags) to commit hashes.Nz refs/remotes/z refs/heads/z refs/tags/)r]r^rr_r`)r"r;rXÚrvr[r\Zref_namer+r+r,r=Ós    zGit.get_short_refscCs¤|jddgd|d�jƒ}tjj|ƒs2tjj||ƒ}tjj|dƒ}|}xBtjjtjj|dƒƒs†|}tjj|ƒ}||krFtj d|ƒdSqFWt ||ƒr–dStjj ||ƒS) z:Return the relative path of setup.py to the git repo root.z rev-parsez --git-dirF)r.r8z..zsetup.pyzGCould not find setup.py for directory %s (tried all parent directories)N) r2rQÚosr'Úisabsr4ÚexistsÚdirnamer>r?rÚrelpath)r"r;Zgit_dirZroot_dirZ orig_locationZ last_locationr+r+r,Ú_get_subdirectoryâs"    zGit._get_subdirectorycCsr|j|ƒ}|jƒjdƒs d|}|jƒjddƒd}|sÚdebug)Úclsr;Úr)r*r+r,rp$s zGit.controls_location)r rrrrr)N)r/)r/)Ú__name__Ú __module__Ú __qualname__ÚnamerhZ repo_nameZschemesr!r7r<rCrErIrKrNrRrDr]r^r_r`rbrcr=rjrmrLrHÚ classmethodrpÚ __classcell__r+r+)r*r,r s4       r )Z __future__rZloggingr9Zos.pathreZ pip.compatrZpip.exceptionsrZpip._vendor.six.moves.urllibrZ urllib_parserrZpip._vendor.packaging.versionr6Z pip.utilsrrZpip.vcsr r rrZ getLoggerrtr>r Úregisterr+r+r+r,Ús"