a [fE@sddlZddlZddlZddlZddlZddlZddlm Z m Z m Z ddl m Z mZddlmZmZmZddlmZddlmZmZmZmZmZmZmZejjZejjZe e!Z"e#dZ$e#dZ%e#d ej&Z'e(e)d d d Z*Gd ddeZ+e,e+dS)N)ListOptionalTuple) BadCommandInstallationError) HiddenText display_pathhide_url) make_command)AuthInfoRemoteNotFoundErrorRemoteNotValidError RevOptionsVersionControl(find_path_to_project_root_from_repo_rootvcsz(^git version (\d+)\.(\d+)(?:\.(\d+))?.*$z^[a-fA-F0-9]{40}$a/^ # Optional user, e.g. 'git@' (\w+@)? # Server, e.g. 'github.com'. ([^/:]+): # The server-side path. e.g. 'user/project.git'. Must start with an # alphanumeric character so as not to be confusable with a Windows paths # like 'C:/foo/bar' or 'C:\foo\bar'. (\w[^:]*) $)shareturncCstt|SN)bool HASH_REGEXmatch)rr9/usr/lib/python3.9/site-packages/pip/_internal/vcs/git.pylooks_like_hash7srcseZdZdZdZdZdZdZdZe e e e ddd Z e e e d d d Zeed fdddZee ee dddZee e eee e fdddZee e e dddZee eeedddZee ee e dddZe eeddd d!Ze eeddd"d#Ze eeddd$d%Zee e dd&d'Ze e e d(d)d*Zee e e d+d,d-Z ed;e ee e d+d.d/Z!ee ee dd0d1Z"ee ee ee e#fd(fd2d3 Z$ee ddd4d5Z%ee ee dfd6d7 Z&e e e d8d9d:Z'Z(S)<Gitgitz.gitclone)zgit+httpz git+httpszgit+sshzgit+gitzgit+file)ZGIT_DIRZ GIT_WORK_TREEHEAD)revrcCs|gSrrrrrrget_base_rev_argsKszGit.get_base_rev_args)urldestrcCsJ|t|\}}|jsdS|||js.dSt|||jd}| S)NFr)Zget_url_rev_optionsr ris_commit_id_equalrget_revision_sha)selfr"r#_ rev_optionsZis_tag_or_branchrrris_immutable_rev_checkoutOszGit.is_immutable_rev_checkout.)rcCsF|jdgddd}t|}|s0td|dStdd|DS) NversionFT) show_stdout stdout_onlyzCan't parse git version: %srcss|]}t|VqdSr)int).0crrr cz&Git.get_git_version..) run_commandGIT_VERSION_REGEXrloggerwarningtuplegroups)r&r*rrrrget_git_version]s   zGit.get_git_version)locationrcCsBgd}|j|ddd|d}|}|dr>|tddSdS)zl Return the current branch, or None if HEAD isn't at a branch (e.g. detached HEAD). )z symbolic-ref-qrFTZextra_ok_returncodesr+r,cwdz refs/heads/N)r2strip startswithlen)clsr9argsoutputrefrrrget_current_branches  zGit.get_current_branch)r#rrc Cs|jd|g|dddd}i}|dD]T}|d}|s>q*z|jdd d \}}Wn tyttd |Yn0|||<q*d |}d |} ||} | dur| dfS|| } | 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-refFTignore)r>r+r, on_returncode   )maxsplitzunexpected show-ref line: zrefs/remotes/origin/z refs/tags/N)r2r?splitrstrip ValueErrorget) rBr#rrDZrefslineZref_shaZref_nameZ branch_refZtag_refrrrrr%~s0        zGit.get_revision_shacCs.|drdSt|sdS|||r*dSdS)a$ Return true if rev is a ref or is a commit that we don't have locally. Branches and tags are not considered in this method because they are assumed to be always available locally (which is a normal outcome of ``git clone`` and ``git fetch --tags``). zrefs/TF)r@r has_commit)rBr#rrrr _should_fetchs  zGit._should_fetch)r#r"r(rcCs|j}|dusJ|||\}}|durF||}|r<|nd|_|St|sZtd||||sj|S|jt dd|| |d|j |dd}||}|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.fetchr:r>Z FETCH_HEADr ) Zarg_revr%make_new branch_namerr4r5rTr2r to_args get_revision)rBr#r"r(rrZ is_branchrrrresolve_revisions*     zGit.resolve_revision)r#namercCs|sdS|||kS)z Return whether the current commit hash equals the given name. Args: dest: the repository directory. name: a string name. F)rZ)rBr#r\rrrr$s zGit.is_commit_id_equalNc Cs |}td||t||dkr@|tddd||n|tdd|||jr||||}t |dd}t d|||dur| ||jstdd| }|j||d n4| ||krd |}dd |d |g}|j||d n||}||}td ||j||dS)NzCloning %s%s to %s)rLrz--filter=blob:noner:rXzRev options %s, branch_name %scheckoutrVzorigin/z-bz--trackzResolved %s to commit %s)Z to_displayr4inforr8r2r rr[getattrdebugr$rYrFrZrWupdate_submodules) r&r#r"r(Z rev_displayrXcmd_argsZ track_branchrrrr fetch_newsL      z Git.fetch_newcCsB|jtdd||dtdd|}|j||d||dS)Nconfigzremote.origin.urlrVr^r:)r2r rYrbr&r#r"r(rcrrrswitch7s z Git.switchcCsn|dkr |jgd|dn|jddg|d||||}tddd|}|j||d||dS)N)r< )rUr:z--tagsrVrUr:resetz--hard)r8r2r[r rYrbrfrrrupdateAs z Git.updatecCs||jgdddd|d}|}z |d}WntyBtYn0|D]}|drH|}q`qH|dd }||S) z Return URL of the first remote encountered. Raises RemoteNotFoundError if the repository does not have a remote url configured. )rez --get-regexpzremote\..*\.urlr;FTr=rzremote.origin.url rKr<)r2 splitlines IndexErrorr r@rN_git_remote_to_pip_urlr?)rBr9stdoutZremotesZ found_remoteZremoter"rrrget_remote_urlOs$     zGit.get_remote_url)r"rcCsNtd|r|Stj|r*t|St|}|rB| dSt |dS)a8 Convert a remote url from what git uses to what pip accepts. There are 3 legal forms **url** may take: 1. A fully qualified url: ssh://git@example.com/foo/bar.git 2. A local project.git folder: /path/to/bare/repository.git 3. SCP shorthand for form 1: git@example.com:foo/bar.git Form 1 is output as-is. Form 2 must be converted to URI and form 3 must be converted to form 1. See the corresponding test test_git_remote_url_to_pip() for examples of sample inputs/outputs. z\w+://z ssh://\1\2/\3N) rerospathexistspathlibPurePathas_uri SCP_REGEXexpandr )r"Z scp_matchrrrrmms    zGit._git_remote_to_pip_url)r9rrcCs>z |jdddd|g|ddWnty4YdS0dSdS) zU Check if rev is a commit that is available in the local repository. rev-parser:z--verifyzsha^F)r>log_failed_cmdTN)r2r)rBr9rrrrrSs  zGit.has_commitcCs*|dur d}|jd|gdd|d}|S)NrryFTr+r,r>)r2r?)rBr9rZ current_revrrrrZszGit.get_revisioncCsT|jddgdd|d}tj|s4tj||}tjtj|d}t||S)z Return the path to Python project root, relative to the repo root. Return None if the project root is in the repo root. ryz --git-dirFTr{z..)r2r?rqrrisabsjoinabspathr)rBr9Zgit_dirZ repo_rootrrrget_subdirectorys  zGit.get_subdirectoryc st|\}}}}}|dr|dt|d }|tj|ddd}|dd} |d| t || d||||f}d|vrd|vsJ|d d }t |\}} } |d d }nt |\}} } || | 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. fileN/\+r<z://zfile:zgit+z git+ssh://zssh://) urlsplitendswithrAlstripurllibZrequestZ url2pathnamereplacefind urlunsplitsuperget_url_rev_and_auth) rBr"schemenetlocrrqueryfragmentinitial_slashesnewpathZ after_plusrZ user_pass __class__rrrs&     zGit.get_url_rev_and_authcCs0tjtj|dsdS|jgd|ddS)Nz .gitmodules)Z submodulerjz--initz --recursiver:rV)rqrrrsr}r2)rBr9rrrrbs zGit.update_submodulescsxt|}|r|Sz|jddg|ddddd}Wn2tyRtd|YdStydYdS0tj | dS) Nryz--show-toplevelFTraise)r>r+r,rHrzzKcould not determine if %s is under git control because git is not availablez ) rget_repository_rootr2rr4rarrqrrnormpathrO)rBr9locrrrrrs*    zGit.get_repository_root)repo_urlrcCsdS)zEIn either https or ssh form, requirements must be prefixed with git+.Tr)rrrrshould_add_vcs_url_prefixszGit.should_add_vcs_url_prefix)N))__name__ __module__ __qualname__r\dirnameZ repo_nameZschemesZ unset_environZdefault_arg_rev staticmethodstrrr!rr)rr-r8 classmethodrrFr%rTrrr[r$rdrgrjrormrSrZrr rrbrr __classcell__rrrrr;sV  --7  $r)-ZloggingZos.pathrqrtrp urllib.parserZurllib.requesttypingrrrZpip._internal.exceptionsrrZpip._internal.utils.miscrrr Zpip._internal.utils.subprocessr Z pip._internal.vcs.versioncontrolr r r rrrrparserrZ getLoggerrr4compiler3rVERBOSErwrrrrregisterrrrrs6 $    I