3 . g+@sddlmZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Zddlm ZddlmZmZddlmZmZe jZe jZejeZGd d d eZejedS) )absolute_importN)samefile) BadCommand)parse)request) display_pathrmtree)vcsVersionControlcseZdZdZdZdZd6Zd7fd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zfd0d1Zd2d3Zefd4d5ZZS)8Gitgitz.gitclonegit+http git+httpsgit+sshgit+gitgit+fileNc s|rt|\}}}}}|jdr|dt|jd } | tj|jddjd} t||| ||f}|jdd} |d| t|| d|| ||f}t t |j |f||dS)Nfile/\+) urlsplitendswithlenlstripurllib_requestZ url2pathnamereplace urlunsplitfindsuperr __init__) selfurlargskwargsschemeZnetlocpathZqueryZfragmentinitial_slashesnewpathZ after_plus) __class__/usr/lib/python3.6/git.pyr! s   z Git.__init__cCsTd}|jdgdd}|j|r0|t|d}nd}dj|jddd}t|S)Nz git version versionF) show_stdout.) run_command startswithrjoinsplit parse_version)r"Z VERSION_PFXr-r+r+r,get_git_version5s zGit.get_git_versionc CsVtjdd}|j|z0|jds*|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)tempfileZmkdtempunpackrr2r)r"locationZtemp_dirr+r+r,exportBs    z Git.exportcCsJ|j|}d|}||kr$||gS||kr6||gStjd||SdS)zCheck 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_refsloggerwarning)r"revdest rev_optionsZ revisionsZ origin_revr+r+r,check_rev_optionsOs   zGit.check_rev_optionscCs|j|j|dS)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)Nconfigzremote.origin.url)r8checkoutz-q)r2update_submodules)r"rAr#rBr+r+r,switchlsz Git.switchcCst|jtdkr&|jdddg|dn|jddg|d|rN|j|d||}|jdddg||d|j|dS) Nz1.9.0Zfetchz-qz--tags)r8rresetz--hard)r7r6r2rCrH)r"rArBr+r+r,updatersz Git.updatecCs|j\}}|r |g}d|}n dg}d}|j||||rtjd||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,obtains"    z Git.obtaincCsZ|jdddgd|d}|j}|d}x|D]}|jdr,|}Pq,W|jdd }|jS) z+Return URL of the first remote encountered.rFz --get-regexpzremote\..*\.urlF)r.r8rzremote.origin.url  r)r2 splitlinesr3r5strip)r"r;ZremotesZ found_remoteZremoter#r+r+r,get_urls   z Git.get_urlcCs|jddgd|d}|jS)Nz rev-parseZHEADF)r.r8)r2rQ)r"r; current_revr+r+r,rDszGit.get_revisionccsN|jdgd|d}x6|jjD]&}|jdd\}}|j|jfVq WdS)z4Yields tuples of (commit, ref) for branches and tagszshow-refF)r.r8rOrN)r2rQrPr5)r"r;outputlinecommitrefr+r+r, get_full_refss  zGit.get_full_refscCs |jdS)Nz refs/remotes/)r3)r"rWr+r+r, is_ref_remoteszGit.is_ref_remotecCs |jdS)Nz refs/heads/)r3)r"rWr+r+r, is_ref_branchszGit.is_ref_branchcCs |jdS)Nz refs/tags/)r3)r"rWr+r+r, is_ref_tagszGit.is_ref_tagcCs"t|j||j||j|f S)z0A ref is a commit sha if it is not anything else)anyrYrZr[)r"rWr+r+r, is_ref_commitszGit.is_ref_commitcCs |j|S)N)r=)r"r;r+r+r,get_refssz Git.get_refscCsi}x||j|D]n\}}d}|j|r8|tdd}n6|j|rT|tdd}n|j|rn|tdd}|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/)rXrYrrZr[)r"r;rvrVrWZref_namer+r+r,r=s    zGit.get_short_refscCs|jddgd|dj}tjj|s2tjj||}tjj|d}|}xBtjjtjj|ds|}tjj|}||krFtj d|dSqFWt ||rdStjj ||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) r2rQosr'isabsr4existsdirnamer>r?rrelpath)r"r;Zgit_dirZroot_dirZ orig_locationZ last_locationr+r+r,_get_subdirectorys"    zGit._get_subdirectorycCsr|j|}|jjds d|}|jjddd}|sdebug)clsr;r)r*r+r,rks zGit.controls_location)r rrrrr)N)__name__ __module__ __qualname__namercZ repo_nameZschemesr!r7r<rCrErIrKrNrRrDrXrYrZr[r]r^r=rerhrLrH classmethodrk __classcell__r+r+)r*r,r s4     r )Z __future__rZloggingr9Zos.pathr`Z pip.compatrZpip.exceptionsrZpip._vendor.six.moves.urllibrZ urllib_parserrZpip._vendor.packaging.versionr6Z pip.utilsrrZpip.vcsr r rrZ getLoggerror>r registerr+r+r+r,s"