3 (\2@sddlmZddlZddlZddlZddlmZddl mZ ddl m Z ddl mZddlmZddlmZmZddlmZdd lmZmZmZe jZe jZejeZejd Z d d Z!Gd ddeZ"ej#e"dS))absolute_importN)parse)request) BadCommand)samefile) display_pathredact_password_from_url) TempDirectory)RemoteNotFoundErrorVersionControlvcsz[a-fA-F0-9]{40}cCsttj|S)N)bool HASH_REGEXmatch)sharh/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-build-k1a8l1r5/pip/pip/_internal/vcs/git.pylooks_like_hashsrcseZdZdZdZdZd/Zd0Zd Zd1fd d Z e ddZ ddZ e ddZddZe ddZe ddZe ddZe ddZdd Zd!d"Ze d#d$Ze d2d%d&Ze d'd(Ze fd)d*Ze d+d,Ze fd-d.ZZS)3Gitgitz.gitclonegit+http git+httpsgit+sshgit+gitgit+fileGIT_DIR GIT_WORK_TREEHEADNc 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__rrr.+s   z Git.__init__cCs|gS)Nr)revrrrget_base_rev_args@szGit.get_base_rev_argscCs\d}|jdgdd}|j|r8|t|djd}nd}dj|jddd}t|S) Nz git version versionF) show_stdoutr.) run_command startswithr&splitjoin parse_version)r/ VERSION_PFXr>rrrget_git_versionDs zGit.get_git_versioncCsBdddg}|j|d d|d}|j}|jdr>|tddSdS) zl Return the current branch, or None if HEAD isn't at a branch (e.g. detached HEAD). z symbolic-refz-qrr#F)extra_ok_returncodesr?cwdz refs/heads/N)r#)rCstriprDr&)clslocationr1outputrefrrrget_current_branchQs  zGit.get_current_branchc CsT|jds|d}tdd.}|j|j|jdddd|gd|jd Wd QRXd S) z@Export the Git repository at the url to the destination locationr export)kindzcheckout-indexz-az-fz--prefixF)r?rKN)r%r unpackr5rC)r/rNtemp_dirrrrrRfs    z Git.exportc Cs|jd|g|ddd}i}xP|jjD]@}y|j\}}Wn"tk r^tdj|YnX|||<q(Wdj|}dj|} |j|}|dk r|d fS|j| }|dfS) z Return (sha_or_none, is_branch), where sha_or_none is a commit hash if the revision names a remote branch or tag, otherwise None. Args: dest: the repository directory. rev: the revision name. zshow-refFignore)rKr? on_returncodezunexpected show-ref line: {!r}zrefs/remotes/origin/{}z refs/tags/{}NT)rCrL splitlinesrE ValueErrorformatget) rMdestr<rOrefslinerrPZ branch_refZtag_refrrrget_revision_shars       zGit.get_revision_shacCs|j}|j||\}}|dk r:|j|}|r0|nd|_|St|sNtjd||jds\|S|jdd|g|j |d|j |dd}|j|}|S) z Resolve a revision to a new RevOptions object with the SHA1 of the branch, tag, or ref if found. Args: rev_options: a RevOptions object. Nz:Did not find branch or tag '%s', assuming revision or ref.zrefs/fetchz-q)rKZ FETCH_HEAD)r<) Zarg_revr_Zmake_new branch_namerloggerwarningrDrCto_args get_revision)rMr\r0 rev_optionsr<rZ is_branchrrrresolve_revisions$    zGit.resolve_revisioncCs|sdS|j||kS)z Return whether the current commit hash equals the given name. Args: dest: the repository directory. name: a string name. F)re)rMr\namerrris_commit_id_equals zGit.is_commit_id_equalcCs|j}tjdt||t||jdd||g|jr|j|||}t|dd}|dkr|j ||jsddg|j }|j||dn4|j ||krdj |}dd|d |g}|j||d|j |dS) NzCloning %s%s to %srz-qracheckout)rKz origin/{}z-bz--track)Z to_displayrbinforrrCr<rggetattrrirdrQrZupdate_submodules)rMr\r0rf rev_displayracmd_argsZ track_branchrrr fetch_news"   z Git.fetch_newcCs@|jdd|g|dddg|j}|j||d|j|dS)Nconfigzremote.origin.url)rKrjz-q)rCrdrm)r/r\r0rfrorrrswitchsz Git.switchcCst|jtdkr&|jdddg|dn|jddg|d|j|||}dddg|j}|j||d|j|dS)Nz1.9.0r`z-qz--tags)rKresetz--hard)rIrGrCrgrdrm)r/r\r0rfrorrrupdatesz Git.updatec Csz|jdddgd d|d}|j}y |d}Wntk rDtYnXx|D]}|jdrL|}PqLW|jd d}|jS) z Return URL of the first remote encountered. Raises RemoteNotFoundError if the repository does not have a remote url configured. rqz --get-regexpzremote\..*\.urlr#F)rJr?rKrzremote.origin.url  )r#)rCrX IndexErrorr rDrErL)rMrNstdoutremotes found_remoteremoter0rrrget_remote_urls      zGit.get_remote_urlcCs(|dkr d}|jd|gd|d}|jS)Nrz rev-parseF)r?rK)rCrL)rMrNr< current_revrrrres zGit.get_revisioncCs|jddgd|dj}tjj|s2tjj||}tjj|d}|}xBtjjtjj|ds|}tjj|}||krFtj d|dSqFWt ||rdStjj ||S)Nz rev-parsez --git-dirF)r?rKz..zsetup.pyzGCould not find setup.py for directory %s (tried all parent directories)) rCrLosr5isabsrFexistsdirnamerbrcrrelpath)rMrNgit_dirroot_dir orig_location last_locationrrrget_subdirectory$s"    zGit.get_subdirectorycsdd|krDd|kst|jdd}tt|j|\}}}|jdd}ntt|j|\}}}|||fS)a9 Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'. That's required because although they use SSH they sometimes don'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://r@)AssertionErrorr*r-rget_url_rev_and_auth)rMr0r< user_pass)r;rrr?s  zGit.get_url_rev_and_authcCs6tjjtjj|dsdS|jdddddg|ddS)Nz .gitmodules submodulertz--initz --recursivez-q)rK)r}r5rrFrC)rMrNrrrrmQs  zGit.update_submodulesc sTtt|j|rdSy|jdg|ddd}| Stk rNtjd|dSXdS)NTz rev-parseFrV)rKr?rWzKcould not determine if %s is under git control because git is not available)r-rcontrols_locationrCrrbdebug)rMrNr)r;rrrZszGit.controls_location)rrrrrr)rr)N)N)__name__ __module__ __qualname__rhr repo_nameschemesZ unset_environZdefault_arg_revr. staticmethodr=rI classmethodrQrRr_rgrirprrrtr{rerrrmr __classcell__rr)r;rrs0   # (      r)$ __future__rloggingos.pathr}reZpip._vendor.packaging.versionrrGZpip._vendor.six.moves.urllib urllib_parserr(Zpip._internal.exceptionsrZpip._internal.utils.compatrZpip._internal.utils.miscrrZpip._internal.utils.temp_dirr Zpip._internal.vcsr r r r$r+ getLoggerrrbcompilerrrregisterrrrrs(         M