Y+@sddlmZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Zddlm ZddlmZmZddlmZmZe jZe jZejeZGd d d eZejedS) )absolute_importN)samefile) BadCommand)parse)request) display_pathrmtree)vcsVersionControlcsKeZdZdZdZdZd6Zd fd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zfd0d1Zd2d3Zefd4d5ZS)7Gitgitz.gitclonegit+http git+httpsgit+sshgit+gitgit+fileNc s|rt|\}}}}}|jdr|dt|jd } | tj|jddjd} t||| ||f}|jdd} |d| t|| d|| ||f}t t |j |||dS)Nfile/\+) urlsplitendswithlenlstripurllib_request url2pathnamereplace urlunsplitfindsuperr __init__) selfurlargskwargsschemenetlocpathqueryfragmentinitial_slashesnewpath after_plus) __class__*/tmp/pip-build-3puug3g5/pip/pip/vcs/git.pyr" s #z Git.__init__cCsxd}|jdgdd}|j|rF|t|d}nd}dj|jddd}t|S)Nz git version version show_stdoutF.) run_command startswithrjoinsplit parse_version)r# VERSION_PFXr2r0r0r1get_git_version5s"zGit.get_git_versionc Csvtjdd}|j|zE|jds;|d}|jdddd|gdd d |Wd t|Xd S) z@Export the Git repository at the url to the destination locationz-exportzpip-rzcheckout-indexz-az-fz--prefixr3FcwdN)tempfilemkdtempunpackrr7r)r#locationtemp_dirr0r0r1exportBs  z Git.exportcCs_|j|}d|}||kr0||gS||krG||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_options revisions origin_revr0r0r1check_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_revisionr8)r#rIrJr0r0r1 check_versioncszGit.check_versioncCsJ|jdd|gd||jddg|d||j|dS)Nconfigzremote.origin.urlr>checkoutz-q)r7update_submodules)r#rIr$rJr0r0r1switchlsz Git.switchcCs|jtdkr7|jdddgd|n|jddgd||ro|j|d||}|jdddg|d||j|dS) Nz1.9.0fetchz-qz--tagsr>rresetz--hard)r=r;r7rMrR)r#rIrJr0r0r1updaters z Git.updatecCs|j\}}|r.|g}d|}ndg}d}|j||||rtjd||t||jdd||g|r|j|||}|j||s|jddg|d||j|dS) Nz (to %s)z origin/masterr4zCloning %s%s to %sr z-qrQr>) get_url_revcheck_destinationrFinforr7rMrOrR)r#rIr$rHrJ rev_displayr0r0r1obtains"   z Git.obtaincCs~|jdddgddd|}|j}|d}x$|D]}|jdrA|}PqAW|jd d }|jS) z+Return URL of the first remote encountered.rPz --get-regexpzremote\..*\.urlr3Fr>rzremote.origin.url  r)r7 splitlinesr8r:strip)r#rBremotes found_remoteremoter$r0r0r1get_urls   z Git.get_urlcCs+|jddgddd|}|jS)Nz rev-parseHEADr3Fr>)r7r^)r#rB current_revr0r0r1rNszGit.get_revisionccsn|jdgddd|}xI|jjD]5}|jdd\}}|j|jfVq1WdS)z4Yields tuples of (commit, ref) for branches and tagszshow-refr3Fr>r\rN)r7r^r]r:)r#rBoutputlinecommitrefr0r0r1 get_full_refss zGit.get_full_refscCs |jdS)Nz refs/remotes/)r8)r#rhr0r0r1 is_ref_remoteszGit.is_ref_remotecCs |jdS)Nz refs/heads/)r8)r#rhr0r0r1 is_ref_branchszGit.is_ref_branchcCs |jdS)Nz refs/tags/)r8)r#rhr0r0r1 is_ref_tagszGit.is_ref_tagcCs/t|j||j||j|f S)z0A ref is a commit sha if it is not anything else)anyrjrkrl)r#rhr0r0r1 is_ref_commits  zGit.is_ref_commitcCs |j|S)N)rE)r#rBr0r0r1get_refssz Git.get_refscCsi}x|j|D]\}}d}|j|rP|tdd}nM|j|rx|tdd}n%|j|r|tdd}|dk r|||z..zsetup.pyzGCould not find setup.py for directory %s (tried all parent directories)N) r7r^osr)isabsr9existsdirnamerFrGrrelpath)r#rBgit_dirroot_dir orig_location last_locationr0r0r1_get_subdirectorys"$ zGit._get_subdirectorycCs|j|}|jjds.d|}|jjddd}|sTdS|j|}d|||f}|j|}|r|d|7}|S)Nzgit:zgit+-rrz %s@%s#egg=%sz&subdirectory=)rblowerr8egg_namer:rNr{)r#distrBrepoegg_project_namerdreq subdirectoryr0r0r1get_src_requirements zGit.get_src_requirementcsd|jkrld|jks$t|jjdd|_tt|j\}}|jdd}ntt|j\}}||fS)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://zfile:zgit+z git+ssh://zssh://r4)r$AssertionErrorrr!r rW)r#r$rH)r/r0r1rWszGit.get_url_revcCsKtjjtjj|ds%dS|jdddddgd|dS)Nz .gitmodules submodulerVz--initz --recursivez-qr>)rrr)rtr9r7)r#rBr0r0r1rRs !zGit.update_submodulescsytt|j|rdSy0|jdgd|dddd}| SWn&tk rttjd|dSYnXdS) NTz rev-parser>r3F on_returncodeignorezKcould not determine if %s is under git control because git is not available)r!r controls_locationr7rrFdebug)clsrBr)r/r0r1rs    zGit.controls_location)zgitrrrrr)__name__ __module__ __qualname__nameru repo_nameschemesr"r=rDrMrOrSrVr[rbrNrirjrkrlrnrorEr{rrWrR classmethodrr0r0)r/r1r s4                r ) __future__rloggingr?os.pathrr pip.compatrpip.exceptionsrZpip._vendor.six.moves.urllibr urllib_parserrZpip._vendor.packaging.versionr; pip.utilsrrpip.vcsr r rr getLoggerrrFr registerr0r0r0r1s