3 Pf,-@sddlmZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Zddlm ZddlmZmZddlmZmZe jZe jZejeZGd d d eZejedS) )absolute_importN)samefile) BadCommand)parse)request) display_pathrmtree)vcsVersionControlcseZdZdZdZdZd7Zd8fd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZd9dd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd:d+d,Zd-d.Zd/d0Zfd1d2Zd3d4Zefd5d6ZZS);Gitgitz.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.exportcCsL|j||}d|}||kr&||gS||kr8||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_revisionr/c cs|jd|gd|d}xl|jdD]^}|jd}|s4q y|jdd\}}Wn"tk rjtd|YnX|j|jfVq Wd S) z4Yields tuples of (commit, ref) for branches and tagszshow-refF)r.r8  rOrzunexpected show-ref line: N)r2r5rstrip ValueErrorrQ)r"r;patternoutputlinecommitrefr+r+r, get_full_refss   zGit.get_full_refscCs |jdS)Nz refs/remotes/)r3)r"r\r+r+r, is_ref_remoteszGit.is_ref_remotecCs |jdS)Nz refs/heads/)r3)r"r\r+r+r, is_ref_branchszGit.is_ref_branchcCs |jdS)Nz refs/tags/)r3)r"r\r+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)anyr^r_r`)r"r\r+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|r:|tdd}n6|j|rV|tdd}n|j|rp|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/)r]r^rr_r`)r"r;rXrvr[r\Zref_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,ro$s zGit.controls_location)r rrrrr)N)r/)r/)__name__ __module__ __qualname__namerhZ repo_nameZschemesr!r7r<rCrErIrKrNrRrDr]r^r_r`rbrcr=rjrmrLrH classmethodro __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 getLoggerrsr>r registerr+r+r+r,s"