7iFddlZddlZddlZddlZddlZddlZddlm Z m Z m Z ddl m Z mZddlmZmZmZddlmZddlmZmZmZmZmZmZmZej:j<Zej:j>Zej@e!Z"ejFdZ$ejFdZ%ejFd ejLZ'd e(d e)fd Z*Gd deZ+ejXe+y)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[^:]*) $shareturnc>ttj|SN)bool HASH_REGEXmatch)rs ^/mnt/ssd/data/python-lab/ChefSystem/venv/lib/python3.12/site-packages/pip/_internal/vcs/git.pylooks_like_hashr7s    % &&c eZdZdZdZdZdZdZdZe de de e fd Z d e d e de fd Zdeed ffdZede dee fdZed e de deee e ffdZed e de de fdZed e d ededefdZed e dee de fdZd e d edededdf dZd e d ededdfdZd e d ededdfdZede de fdZe d e de fdZede de de fdZ ed&de dee de fdZ!ede dee fd Z"ed e dee ee e#fffd! Z$ede ddfd"Z%ede dee ffd# Z&e d$e de fd%Z'xZ(S)'Gitgitz.gitclone)zgit+httpz git+httpszgit+sshzgit+gitzgit+file)GIT_DIR GIT_WORK_TREEHEADrevrc|gSrr$s rget_base_rev_argszGit.get_base_rev_argsKs u rurldestc|jt|\}}|jsy|j||jsyt |j ||jd}| S)NFr)get_url_rev_optionsr r$is_commit_id_equalrget_revision_sha)selfr)r*_ rev_optionsis_tag_or_branchs ris_immutable_rev_checkoutzGit.is_immutable_rev_checkoutOsi11(3-@;&&t[__=  5 5dKOO LQ OP###r.c|jdgddd}tj|}|stj d|yt |j dt |j d fS) Nversionz git versionFT) command_desc show_stdout stdout_onlyzCan't parse git version: %sr&) run_commandGIT_VERSION_REGEXrloggerwarningintgroup)r/r5rs rget_git_versionzGit.get_git_version]sq"" K& #  "''0 NN8' BEKKN#SQ%899rlocationcgd}|j|ddd|}|j}|jdr|tddSy)zl Return the current branch, or None if HEAD isn't at a branch (e.g. detached HEAD). )z symbolic-ref-qr#r9FTextra_ok_returncodesr7r8cwdz refs/heads/N)r;strip startswithlen)clsrBargsoutputrefs rget_current_branchzGit.get_current_branchjsZ. !% ! lln >>- (s=)+, ,rc|jd|g|ddd}i}|jjdD]2}|jd}|s |jdd \}}|||<4d |}d |} |j |} | | dfS|j | } | dfS#t$rt d |wxYw)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)rHr7r8 on_returncode   r:)maxsplitzunexpected show-ref line: zrefs/remotes/origin/z refs/tags/)r;rIsplitrstrip ValueErrorget) rLr*r$rNrefslineref_sharef_name branch_reftag_refrs rr.zGit.get_revision_shas  " ! LLN((. %D;;t$D H$(JJsQJ$?! %DN %,C51 se$hhz" ?; hhwU|! H!#=dX!FGG Hs B%%B=cf|jdryt|sy|j||ryy)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)rJr has_commit)rLr*r$s r _should_fetchzGit._should_fetchs2 >>' "s# >>$ $rr1c |j}|J|j||\}}|%|j|}|r ||_|Sd|_|St |st j d||j||s|S|jtdd||j||j|d}|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.fetchrDrH FETCH_HEADr') arg_revr.make_new branch_namerr=r>rdr;r to_args get_revision)rLr*r)r1r$r is_branchs rresolve_revisionzGit.resolve_revisions!!--dC8Y ?%..s3K-6cK # =AK # s# NNL    s+   $[-@-@-B C  t6!**3/ rnamec0|sy|j||k(S)z Return whether the current commit hash equals the given name. Args: dest: the repository directory. name: a string name. F)rm)rLr*rps rr-zGit.is_commit_id_equals %--r verbosityNc`|j}tjd||t||dkrd}n |dk(rd}nd}|j dk\r!|j t dd g|||n|j t dg||||jr|j|||}t|d d}tjd |||K|j||jst d d |j}|j ||nV|j||k7rBd|} d d|d| g}|j ||n"|j|} |j| }tjd||j|j!|y)NzCloning %s%s to %sr)z--quietr9r&)z --verbosez --progress)r:r z--filter=blob:nonerkzRev options %s, branch_name %scheckoutrDrgzorigin/z-bz--trackzResolved %s to commit %s) to_displayr=infor rAr;r r$rogetattrdebugr-rlrPrmrjupdate_submodules) r/r*r)r1rr rev_displayflagsrkcmd_args track_branchrs r fetch_newz Git.fetch_news",,.  (#{L%1E !^E/E    !W ,   (       \'EEE3EE F ??//c;GK!+}dCK LL9; T"..t[__E+"#++- H $$X4$8((.+=") 6    t 4##D)C%..s3K .[__E t$rc|jtdd||tdd|j}|j|||j|y)Nconfigzremote.origin.urlrgrurD)r;r rlrzr/r*r)r1r}s rswitchz Git.switchDs_  #6 <   D+2E2E2GH t, t$rc&|jdk\r|jgd|n|jddg||j|||}tddd|j }|j|||j |y)N)r9 )rfrDz--tagsrgrfrDresetz--hard)rAr;ror rlrzrs rupdatez Git.updateNs    !V +   6D  A   gt_$  7++D#{C 49L9L9NO t, t$rc"|jgdddd|}|j} |d}|D]}|j ds|}n|j dd }|j |jS#t$rtwxYw) z Return URL of the first remote encountered. Raises RemoteNotFoundError if the repository does not have a remote url configured. )rz --get-regexpzremote\..*\.urlrEFTrFrzremote.origin.url rVr9)r; splitlines IndexErrorr rJrX_git_remote_to_pip_urlrI)rLrBstdoutremotes found_remoteremoter)s rget_remote_urlzGit.get_remote_url\s :!% ! ##% &"1:L F  !56%    %a())#))+66 &% % &s A>>Bctjd|r|Stjj |r#t j |jStj|}|r|jdSt|)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/\3) rerospathexistspathlibPurePathas_uri SCP_REGEXexpandr)r) scp_matchs rrzGit._git_remote_to_pip_urlzsq" 88Is #J 77>># ##C(//1 1OOC( ##$45 5!#&&rcZ |jdddd|zg|dy#t$rYywxYw)zU Check if rev is a commit that is available in the local repository. rev-parserDz--verifyzsha^F)rHlog_failed_cmdT)r;r)rLrBr$s rrczGit.has_commitsG  OOdJ =$  !  s  **cX|d}|jd|gdd|}|jS)Nr#rFTr7r8rH)r;rI)rLrBr$ current_revs rrmzGit.get_revisionsA ;Coo #  &   ""rc\|jddgdd|j}tjj |s tjj ||}tjj tjj |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. rz --git-dirFTrz..)r;rIrrisabsjoinabspathr)rLrBgit_dir repo_roots rget_subdirectoryzGit.get_subdirectorys// + & " %'  ww}}W%ggll8W5GGGOOBGGLL$$?@ 7)LLrct|\}}}}}|jdr|dt|jd }|tj j |jddjdz}|jddz} |d| t|| d||||fz}d|vr>d|vsJ|jd d }t |-|\}} } |jd 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/\+r9z://zfile:zgit+z git+ssh://zssh://) urlsplitendswithrKlstripurllibrequest url2pathnamereplacefind urlunsplitsuperget_url_rev_and_auth) rLr)schemenetlocrqueryfragmentinitial_slashesnewpath after_plusr$ user_pass __class__s rrzGit.get_url_rev_and_auths*19 -eX ??6 ""#;c$++c*:&;%;s"C Ci++h+C"''">s"C CiC""rctjjtjj|dsy|j gd|y)Nz .gitmodules) submodulerz--initz --recursiverDrg)rrrrr;)rLrBs rrzzGit.update_submoduless;ww~~bggll8]CD   B  rct||}|r|S |jddg|dddd}tjj|jdS#t$rtj d|Yyt $rYywxYw) Nrz--show-toplevelFTraise)rHr7r8rSrzKcould not determine if %s is under git control because git is not availablez ) rget_repository_rootr;rr=ryrrrnormpathrY)rLrBlocrrs rrzGit.get_repository_rootsg)(3 J /0! %$  A"ww 011  LL/     sAB >B B repo_urlcy)zEIn either https or ssh form, requirements must be prefixed with git+.Tr&)rs rshould_add_vcs_url_prefixzGit.should_add_vcs_url_prefixsrr))__name__ __module__ __qualname__rpdirname repo_nameschemes unset_environdefault_arg_rev staticmethodstrrr(rr3rr?rA classmethodrrPr.rdrrror-rrrrrrcrmrr rrzrr __classcell__)rs@rrr;s0 DGIG1MOstCy $S $ $ $ :sCx :#(3-0+C+c+eHSM4rs ((BGG7 <<  \\ $ $    8 $BJJ RZZ+ ,  BJJ  JJ  '''P.Pf  Sr