Re6@sddlmZddlZddlZddlZddlmZddl mZ ddl m Z ddl mZmZddlmZmZddlmZddlmZdd lmZdd lmZmZmZmZer$dd lmZm Z dd lm!Z!dd lm"Z"m#Z#e j$Z$e j%Z%ej&e'Z(ej)dZ*ddZ+GdddeZ,ej-e,dS))absolute_importN)parse)request) BadCommandSubProcessError) display_pathhide_url) make_command) TempDirectory)MYPY_CHECK_RUNNING)RemoteNotFoundErrorVersionControl!find_path_to_setup_from_repo_rootvcs)OptionalTuple) HiddenText)AuthInfo RevOptionsz^[a-fA-F0-9]{40}$cCsttj|S)N)bool HASH_REGEXmatch)shar/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_internal/vcs/git.pylooks_like_hash*srcsQeZdZdZdZdZd/Zd0Zd Ze d d Z ddZ ddZ e ddZddZe ddZe ddZe ddZddZddZd d!Ze d"d#Ze d$d%d&Ze d'd(Ze fd)d*Ze d+d,Ze fd-d.ZS)1Gitgitz.gitclonegit+http git+httpsgit+sshgit+gitgit+fileGIT_DIR GIT_WORK_TREEHEADcCs|gS)Nr)revrrrget_base_rev_args:szGit.get_base_rev_argscCse|jt|\}}|js(dS|j||jsAdSt|j||jd}| S)NFr)get_url_rev_optionsrr'is_commit_id_equalrget_revision_sha)selfurldest_ rev_optionsis_tag_or_branchrrris_immutable_rev_checkout>s zGit.is_immutable_rev_checkoutcCs|d}|jdg}|j|rJ|t|djd}nd}dj|jddd}t|S)Nz git version versionr.) run_command startswithlensplitjoin parse_version)r, VERSION_PFXr3rrrget_git_versionOs#"zGit.get_git_versioncCs]dddg}|j|dd d|}|j}|jdrY|tddSdS) zl Return the current branch, or None if HEAD isn't at a branch (e.g. detached HEAD). z symbolic-refz-qr&extra_ok_returncodescwdz refs/heads/N)r@)r7stripr8r9)clslocationargsoutputrefrrrget_current_branch\s  zGit.get_current_branchc Csq|jds|d}tddB}|j|jd||jdddd|gd |jWd QRXd S) z@Export the Git repository at the url to the destination location/kindexportr-zcheckout-indexz-az-fz--prefixrAN)endswithr unpackpathr7)r,rDr-temp_dirrrrrKqs z Git.exportc Csd}y|jd|gd|}Wntk r9YnXi}xd|jjD]P}y|j\}}Wn'tk rtdj|YnX|||r<r7rcr r`ri)r,r.r-r0rkrrrupdate sz Git.updatec Cs|jdddgdd d|}|j}y|d}Wntk rXtYnXx$|D]}|jdr`|}Pq`W|jd d}|jS) z Return URL of the first remote encountered. Raises RemoteNotFoundError if the repository does not have a remote url configured. rnz --get-regexpzremote\..*\.urlr?r@rArzremote.origin.url  )r@)r7rP IndexErrorr r8r:rB)rCrDstdoutremotes found_remoteremoter-rrrget_remote_urls     zGit.get_remote_urlNcCs7|dkrd}|jd|gd|}|jS)Nr&z rev-parserA)r7rB)rCrDr' current_revrrrra5s  zGit.get_revisioncCsv|jddgd|j}tjj|sHtjj||}tjjtjj|d}t||S)z~ Return the path to setup.py, relative to the repo root. Return None if setup.py is in the repo root. z rev-parsez --git-dirrAz..)r7rBosrNisabsr;abspathr)rCrDgit_dir repo_rootrrrget_subdirectory>s !zGit.get_subdirectoryc sgt|\}}}}}|jdr|dt|jd }|tj|jddjd}t|||||f}|jdd} |d| t|| d||||f}d|kr9d|kst |jd d }t t |j |\}} } |jd d }n!t t |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. fileNrI\+r@z://zfile:zgit+z git+ssh://zssh://r4) urlsplitrLr9lstripurllib_request url2pathnamereplace urlunsplitfindr[superrget_url_rev_and_auth) rCr-schemenetlocrNqueryfragmentinitial_slashesnewpath after_plusr' user_pass) __class__rrrMs"  # !!zGit.get_url_rev_and_authcCsKtjjtjj|ds%dS|jdddddgd|dS)Nz .gitmodules submodulerqz--initz --recursivez-qrA)rzrNexistsr;r7)rCrDrrrrips !zGit.update_submodulesc stt|j|}|r"|Sy%|jddgd|dd}Wn;tk rotjd|dSYntk rdSYnXtj j |j dS)Nz rev-parsez--show-toplevelrAlog_failed_cmdFzKcould not determine if %s is under git control because git is not availablez ) rrget_repository_rootr7rr^debugrrzrNnormpathrstrip)rCrDlocr)rrrrys      zGit.get_repository_root)rrr r!r"r#)r$r%)__name__ __module__ __qualname__rddirname repo_nameschemes unset_environdefault_arg_rev staticmethodr(r2r> classmethodrHrKr+rcr*rmrorqrxrarrrirrr)rrr.s0    (-  # r). __future__rloggingos.pathrzrepip._vendor.packaging.versionrr<Zpip._vendor.six.moves.urllib urllib_parserrpip._internal.exceptionsrrpip._internal.utils.miscrrpip._internal.utils.subprocessr pip._internal.utils.temp_dirr pip._internal.utils.typingr pip._internal.vcs.versioncontrolr r rrtypingrrrrrrr getLoggerrr^compilerrrregisterrrrrs0   "   `