3 ]+@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_request url2pathnamereplace urlunsplitfindsuperr __init__) selfurlargskwargsschemenetlocpathqueryfragmentinitial_slashesnewpath after_plus) __class__*/tmp/pip-build-8jg9gmni/pip/pip/vcs/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# VERSION_PFXr2r0r0r1get_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)r3cwdN)tempfilemkdtempunpackrr7r)r#locationtemp_dirr0r0r1exportBs    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_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_versioncCs8|jdd|g|d|jddg||d|j|dS)Nconfigzremote.origin.url)r>checkoutz-q)r7update_submodules)r#rIr$rJr0r0r1switchlsz Git.switchcCst|jtdkr&|jdddg|dn|jddg|d|rN|j|d||}|jdddg||d|j|dS) Nz1.9.0fetchz-qz--tags)r>rresetz--hard)r=r;r7rMrR)r#rIrJr0r0r1updatersz 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/masterr4zCloning %s%s to %sr z-qrQ)r>) get_url_revcheck_destinationrFinforr7rMrOrR)r#rIr$rHrJ rev_displayr0r0r1obtains"    z Git.obtaincCsZ|jdddgd|d}|j}|d}x|D]}|jdr,|}Pq,W|jdd }|jS) z+Return URL of the first remote encountered.rPz --get-regexpzremote\..*\.urlF)r3r>rzremote.origin.url  r)r7 splitlinesr8r:strip)r#rBremotes found_remoteremoter$r0r0r1get_urls   z Git.get_urlcCs|jddgd|d}|jS)Nz rev-parseHEADF)r3r>)r7r^)r#rB current_revr0r0r1rNszGit.get_revisionccsN|jdgd|d}x6|jjD]&}|jdd\}}|j|jfVq WdS)z4Yields tuples of (commit, ref) for branches and tagszshow-refF)r3r>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_commitszGit.is_ref_commitcCs |j|S)N)rE)r#rBr0r0r1get_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/)rirjrrkrl)r#rBrvrgrhref_namer0r0r1rEs    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)r3r>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_subdirectorycCsr|j|}|jjds d|}|jjddd}|s)rrr)rtr9r7)r#rBr0r0r1rRs  zGit.update_submodulesc sVtt|j|rdSy|jdg|ddd}| Stk rPtjd|dSXdS)NTz rev-parseFignore)r>r3 on_returncodezKcould not determine if %s is under git control because git is not available)r!r controls_locationr7rrFdebug)clsrBr)r/r0r1rs zGit.controls_location)r rrrrr)N)__name__ __module__ __qualname__nameru repo_nameschemesr"r=rDrMrOrSrVr[rbrNrirjrkrlrnrorEr{rrWrR classmethodr __classcell__r0r0)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"