o gF@sddlZddlZddlZddlZddlZddlZddlm Z m Z m Z ddl m Z mZddlmZmZmZddlmZddlmZmZmZmZmZmZmZejjZejjZe e!Z"e#dZ$e#dZ%e#d ej&Z'd e(d e)fd d Z*GdddeZ+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)rr7/usr/lib/python3/dist-packages/pip/_internal/vcs/git.pylooks_like_hash7src sHeZdZdZdZdZdZdZdZe de de e fd d Z d e d e de fd dZdeedffddZede dee fddZed e de deee e ffddZed e de de fddZed e d ededefddZed e dee de fddZd e d edededd f d!d"Zd e d ededd fd#d$Zd e d ededd fd%d&Zede de fd'd(Ze d e de fd)d*Zede de de fd+d,Z ed:de dee de fd-d.Z!ede dee fd/d0Z"ed e dee ee e#fffd1d2 Z$ede dd fd3d4Z%ede dee ffd5d6 Z&e d7e de fd8d9Z'Z(S);Gitgitz.gitclone)zgit+httpz git+httpszgit+sshzgit+gitzgit+file)GIT_DIR GIT_WORK_TREEHEADrevrcCs|gSrrr!rrrget_base_rev_argsKszGit.get_base_rev_argsurldestcCsJ|t|\}}|jsdS|||jsdSt|||jd}| S)NFr)get_url_rev_optionsr r!is_commit_id_equalrget_revision_sha)selfr$r%_ rev_optionsis_tag_or_branchrrris_immutable_rev_checkoutOszGit.is_immutable_rev_checkout.cCsH|jdgdddd}t|}|std|dStdd |DS) Nversionz git versionFT) command_desc show_stdout stdout_onlyzCan't parse git version: %srcss|]}t|VqdSr)int).0crrr hsz&Git.get_git_version..) run_commandGIT_VERSION_REGEXrloggerwarningtuplegroups)r)r.rrrrget_git_version]s  zGit.get_git_versionlocationcCsBgd}|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-qr FTextra_ok_returncodesr0r1cwdz refs/heads/N)r6strip startswithlen)clsr=argsoutputrefrrrget_current_branchjs  zGit.get_current_branchc Cs|jd|g|dddd}i}|dD](}|d}|sqz |jdd d \}}Wnty8td |w|||<qd |}d |} ||} | durU| 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)rCr0r1 on_returncode   )maxsplitzunexpected show-ref line: zrefs/remotes/origin/z refs/tags/N)r6rDsplitrstrip ValueErrorget) rGr%r!rIrefslineref_sharef_name branch_reftag_refrrrrr(s2        zGit.get_revision_shacCs.|drdSt|s dS|||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)rEr has_commit)rGr%r!rrr _should_fetchs  zGit._should_fetchr+cCs|j}|dus J|||\}}|dur&||}|r!||_|Sd|_|St|s0td||||s8|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>rC FETCH_HEADr") arg_revr(make_new branch_namerr8r9r^r6r to_args get_revision)rGr%r$r+r!r is_branchrrrresolve_revisions.     zGit.resolve_revisionnamecCs|sdS|||kS)z Return whether the current commit hash equals the given name. Args: dest: the repository directory. name: a string name. F)rf)rGr%rirrrr's zGit.is_commit_id_equal verbosityNc CsT|}td||t||dkrd}n |dkrd}nd}|dkr5|tdd g|||Rn|tdg|||R|jr||||}t |d d}t d |||durv| ||jsutd d | }|j||dn%| ||krd|} d d|d| g}|j||dn ||} || }td||j||dS)NzCloning %s%s to %sr)z--quietr@r)z --verbosez --progress)rQrz--filter=blob:nonerdzRev options %s, branch_name %scheckoutr>r`zorigin/z-bz--trackzResolved %s to commit %s) to_displayr8inforr<r6r r!rhgetattrdebugr'rerKrfrcupdate_submodules) r)r%r$r+rj rev_displayflagsrdcmd_args track_branchrrrr fetch_news`      z Git.fetch_newcCsB|jtdd||dtdd|}|j||d||dS)Nconfigzremote.origin.urlr`rlr>)r6r rerqr)r%r$r+rtrrrswitchDs z Git.switchcCsn|dkr|jgd|dn |jddg|d||||}tddd|}|j||d||dS)N)r@ )r_r>z--tagsr`r_r>resetz--hard)r<r6rhr rerqrxrrrupdateNs z Git.updatecCsx|jgdddd|d}|}z|d}Wn tytw|D] }|dr-|}nq"|dd }||S) z Return URL of the first remote encountered. Raises RemoteNotFoundError if the repository does not have a remote url configured. )rwz --get-regexpzremote\..*\.urlr?FTrArzremote.origin.url rPr@)r6 splitlines IndexErrorr rErS_git_remote_to_pip_urlrD)rGr=stdoutremotes found_remoteremoter$rrrget_remote_url\s(    zGit.get_remote_urlcCsJtd|r|Stj|rt|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_matchrrrrzs    zGit._git_remote_to_pip_urlcCs8z|jdddd|g|ddWdStyYdSw)zU Check if rev is a commit that is available in the local repository. rev-parser>z--verifyzsha^F)rClog_failed_cmdT)r6r)rGr=r!rrrr]s zGit.has_commitcCs*|durd}|jd|gdd|d}|S)Nr rFTr0r1rC)r6rD)rGr=r! current_revrrrrfszGit.get_revisioncCsT|jddgdd|d}tj|stj||}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..)r6rDrrisabsjoinabspathr)rGr=git_dir repo_rootrrrget_subdirectorys  zGit.get_subdirectoryc st|\}}}}}|drC|dt|d }|tj|ddd}|dd} |d| t || d||||f}d|vrcd|vsMJ|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/\+r@z://zfile:zgit+z git+ssh://zssh://) urlsplitendswithrFlstripurllibrequest url2pathnamereplacefind urlunsplitsuperget_url_rev_and_auth) rGr$schemenetlocrqueryfragmentinitial_slashesnewpath after_plusr! user_pass __class__rrrs&     zGit.get_url_rev_and_authcCs0tjtj|ds dS|jgd|ddS)Nz .gitmodules) submoduler|z--initz --recursiver>r`)rrrrr6)rGr=rrrrqs  zGit.update_submodulescsxt|}|r |Sz|jddg|ddddd}Wnty)td|YdSty2YdSwtj | dS) Nrz--show-toplevelFTraise)rCr0r1rMrzKcould not determine if %s is under git control because git is not availablez ) rget_repository_rootr6rr8rprrrnormpathrT)rGr=locrrrrrs,   zGit.get_repository_rootrepo_urlcCsdS)zEIn either https or ssh form, requirements must be prefixed with git+.Tr)rrrrshould_add_vcs_url_prefixszGit.should_add_vcs_url_prefixr))__name__ __module__ __qualname__ridirname repo_nameschemes unset_environdefault_arg_rev staticmethodstrrr#rr-rr2r< classmethodrrKr(r^rrrhr'rvryr|rrr]rfrr rrqrr __classcell__rrrrr;sx  $- - ?  &r)-loggingos.pathrrr urllib.parserurllib.requesttypingrrrpip._internal.exceptionsrrpip._internal.utils.miscrrr pip._internal.utils.subprocessr pip._internal.vcs.versioncontrolr r r rrrrparserr getLoggerrr8compiler7rVERBOSErrrrrregisterrrrrs8 $    V