idFddlZddlZddlZddlZddlZddlZddlm Z m Z m Z ddl m Z mZddlmZmZmZddlmZddlmZmZmZmZmZmZmZejjZejjZej e!Z"ej#dZ$ej#dZ%ej#d ej&Z'd e(d e)fd Z*Gd deZ+ej,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[^:]*) $shareturncPtt|SN)bool HASH_REGEXmatch)rs J/opt/cloudlinux/venv/lib/python3.11/site-packages/pip/_internal/vcs/git.pylooks_like_hashr7s    %% & &&c 0eZdZdZdZdZdZdZdZe 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|t|\}}|jsdS|||jsdSt |||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_checkoutOs11(3--@@; 5&&t[_== 5  5 5dKO L LQ OPP###r.c|dgddd}t|}|std|dSt d|DS) Nversionz git versionFT) command_desc show_stdout stdout_onlyzCan't parse git version: %sr&c34K|]}t|VdSr)int).0cs r z&Git.get_git_version..hs(44SVV444444r) run_commandGIT_VERSION_REGEXrloggerwarningtuplegroups)r/r5rs rget_git_versionzGit.get_git_version]s"" K& #   "''00  NN8' B B B244U\\^^444444rlocationcgd}||ddd|}|}|dr|tddSdS)zl Return the current branch, or None if HEAD isn't at a branch (e.g. detached HEAD). )z symbolic-ref-qr#FTextra_ok_returncodesr7r8cwdz refs/heads/N)r>strip startswithlen)clsrEargsoutputrefs rget_current_branchzGit.get_current_branchjsw.-- !% !  llnn >>- ( ( -s=))++, ,trc|d|g|ddd}i}|dD][}|d}|s |dd \}}n #t$rt d |wxYw|||<\d |}d |} ||} | | 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)rLr7r8 on_returncode   )maxsplitzunexpected show-ref line: zrefs/remotes/origin/z refs/tags/)r>rMsplitrstrip ValueErrorget) rPr*r$rRrefslineref_sharef_name branch_reftag_refrs rr.zGit.get_revision_shas6  " !  LLNN((.. % %D;;t$$D  H$(JJsQJ$?$?! H H H!!Fd!F!FGGG H %DNN1C11 $s$$hhz"" ?; hhwU|s !A<<Bc|drdSt|sdS|||rdSdS)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)rNr has_commit)rPr*r$s r _should_fetchzGit._should_fetchsR >>' " " 4s## 5 >>$ $ $ 5trr1c |j}|J|||\}}|"||}|r|nd|_|St |st d||||s|S|tdd|| || |d}||}|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.fetchrGrL FETCH_HEADr') arg_revr.make_new branch_namerr@rArir>r to_args get_revision)rPr*r)r1r$r is_branchs rresolve_revisionzGit.resolve_revisions!--dC88Y ?%..s33K-6&@ccDK # s##  NNL      s++    $[-@-@-B-B C C    t66!**3// rnamec<|sdS|||kS)z Return whether the current commit hash equals the given name. Args: dest: the repository directory. name: a string name. F)rr)rPr*rus rr-zGit.is_commit_id_equals* 5%%--r verbosityNc|}td||t||dkrd}n |dkrd}nd}|dkr&|t dd g|||Rn$|t dg|||R|jr||||}t|d d}t d |||V| ||js:t d d | }|||ng| ||kr#d|} d d|d| g}|||n*||} || }td||j||dS)NzCloning %s%s to %sr)z--quietrIr&)z --verbosez --progress)r[r z--filter=blob:nonerpzRev options %s, branch_name %scheckoutrGrlzorigin/z-bz--trackzResolved %s to commit %s) to_displayr@infor rDr>r r$rtgetattrdebugr-rqrTrrroupdate_submodules) r/r*r)r1rw rev_displayflagsrpcmd_args track_branchrs r fetch_newz Git.fetch_newsW",,..  (#{L>%1EE !^^EE/E    ! !W , ,   (          \'EEE3EEEE F F F ? 4//c;GGK!+}dCCK LL9; T T T"..t[_EE9+"#++--  H $$X4$888((..+== 766    t 444##D))C%..s33K .[_EEE t$$$$$rc|tdd||tdd|}|||||dS)Nconfigzremote.origin.urlrlrzrG)r>r rqrr/r*r)r1rs rswitchz Git.switchDs  #6 < <     D+2E2E2G2GHH t,,, t$$$$$rcj|dkr|gd|n|ddg|||||}tddd|}|||||dS)N)rI )rkrGz--tagsrlrkrGresetz--hard)rDr>rtr rqrrs rupdatez Git.updateNs    ! !V + +   666D  A A A A   gt_$  7 7 7++D#{CC 49L9L9N9NOO t,,, t$$$$$rc`|gdddd|}|} |d}n#t$rtwxYw|D]}|dr|}n|dd }||S) z Return URL of the first remote encountered. Raises RemoteNotFoundError if the repository does not have a remote url configured. )rz --get-regexpzremote\..*\.urlrHFTrJrzremote.origin.url rZrI)r> splitlines IndexErrorr rNr]_git_remote_to_pip_urlrM)rPrEstdoutremotes found_remoteremoter)s rget_remote_urlzGit.get_remote_url\s : : :!% !  ##%% &"1:LL & & &% % &  F  !566 %    %%a())#))++666s ;A c:tjd|r|Stj|r&t j|St|}|r| dSt|)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_urlzs" 8Is # # J 7>>#   2#C((//11 1OOC((  6##$455 5!#&&&rch |dddd|zg|ddS#t$rYdSwxYw)zU Check if rev is a commit that is available in the local repository. rev-parserGz--verifyzsha^F)rLlog_failed_cmdT)r>r)rPrEr$s rrhzGit.has_commitsc  OOdJ =$    4!   55 s # 11ch|d}|d|gdd|}|S)Nr#rFTr7r8rL)r>rM)rPrEr$ current_revs rrrzGit.get_revisionsI ;Coo #  &    """rct|ddgdd|}tj|s tj||}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. rz --git-dirFTrz..)r>rMrrisabsjoinabspathr)rPrEgit_dir repo_roots rget_subdirectoryzGit.get_subdirectorys// + & "  %''  w}}W%% 6gll8W55GGOOBGLL$$?$?@@ 7)LLLrct|\}}}}}|dr|dt|d }|tj|dddz}|ddz} |d| t|| d||||fz}d|vrXd|vsJ|d d }t |\}} } |d d }n%t |\}} } || | 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/\+rIz://zfile:zgit+z git+ssh://zssh://) urlsplitendswithrOlstripurllibrequest url2pathnamereplacefind urlunsplitsuperget_url_rev_and_auth) rPr)schemenetlocrqueryfragmentinitial_slashesnewpath after_plusr$ user_pass __class__s rrzGit.get_url_rev_and_authso19 -eX ??6 " " "#;c$++c*:*:&;&;%;#;">s"C"C Ci++h++CC"'''">">s"C"C CiC""rctjtj|dsdS|gd|dS)Nz .gitmodules) submodulerz--initz --recursiverGrl)rrrrr>)rPrEs rrzGit.update_submoduless^w~~bgll8]CCDD  F  B B B      rc`t|}|r|S |ddg|dddd}n8#t$rtd|YdSt $rYdSwxYwtj | dS) Nrz--show-toplevelFTraise)rLr7r8rWrzKcould not determine if %s is under git control because git is not availablez ) rget_repository_rootr>rr@r~rrrnormpathr^)rPrElocrrs rrzGit.get_repository_rootsgg))(33  J /0! %$  AA    LL/    44    44 w 0 0111sA%A;. A;:A;repo_urlcdS)zEIn either https or ssh form, requirements must be prefixed with git+.Tr&)rs rshould_add_vcs_url_prefixzGit.should_add_vcs_url_prefixs trr))__name__ __module__ __qualname__rudirname repo_nameschemes unset_environdefault_arg_rev staticmethodstrrr(rr3rr:rD classmethodrrTr.rirrrtr-rrrrrrhrrrr rrrr __classcell__)rs@rrr;sf DGIG1MOstCy\ $S $ $ $ $ $ $ 5sCx 5 5 5 5#(3-[0+C+c+eHSM4rs ((((((((((BBBBBBBBGGGGGGGGGG777777 <  \ $   8 $ $BJ RZ+ , ,  BJ  J   ''''''PPPPP.PPPf  Sr