î “ReÚã@s¿ddlZddlZddlZddlmZddlmZmZddlm Z m Z ddl m Z ddl mZmZejZejZGdd„de ƒZe jeƒdS) éN)Úcall_subprocess)Ú display_pathÚrmtree)ÚvcsÚVersionControl)Úlogger)Ú url2pathnameÚurlparsecsßeZdZdZdZdZd&Zd Zd Zd ‡fd d †Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Z‡fd"d#†Zd$d%„Z‡S)'ÚGitÚgitz.gitÚcloneúgit+httpú git+httpsúgit+sshúgit+gitúgit+filez git-clone.txtzs# This was a Git repo; to make it a repo again run: git init git remote add origin %(url)s -f git checkout %(rev)s Nc sü|rÜt|ƒ\}}}}}|jdƒrÜ|dt|jdƒƒ …} | t|ƒjddƒjdƒ} t||| ||fƒ}|jdƒd} |d| …t|| d…|| ||fƒ}qÜntt |ƒj |||ŽdS)NÚfileú/ú\ú+é) ÚurlsplitÚendswithÚlenÚlstriprÚreplaceÚ urlunsplitÚfindÚsuperr Ú__init__) ÚselfÚurlÚargsÚkwargsÚschemeÚnetlocÚpathÚqueryÚfragmentÚinitial_slashesÚnewpathÚ after_plus)Ú __class__©ú&/tmp/pip-ztkk0jow-build/pip/vcs/git.pyrs %9z Git.__init__cCsÃd}}x²|jƒD]¤}|jƒ s|jƒjdƒrEqntjd|ƒ}|ru|jdƒjƒ}ntjd|ƒ}|r¥|jdƒjƒ}n|r|r||fSqWdS)Nú#z$git\s*remote\s*add\s*origin(.*)\s*-frz^git\s*checkout\s*-q\s*(.*)\s*)NN)Ú splitlinesÚstripÚ startswithÚreÚsearchÚgroup)r Úcontentr!ÚrevÚlineÚ url_matchÚ rev_matchr-r-r.Úparse_vcs_bundle_file%s " zGit.parse_vcs_bundle_filecCs…tjddƒ}|j|ƒzT|jdƒs>|d}nt|jdddd|gd|jd d d |ƒWd t|ƒXd S) z@Export the Git repository at the url to the destination locationz-exportzpip-rzcheckout-indexz-az-fz--prefixÚ filter_stdoutÚ show_stdoutFÚcwdN)ÚtempfileÚmkdtempÚunpackrrÚcmdÚ_filterr)r ÚlocationÚtemp_dirr-r-r.Úexport4s  z Git.exportcCs`|j|ƒ}d|}||kr0||gS||krG||gStjd|ƒ|SdS)z¶Check the revision options before checkout to compensate that tags and branches may need origin/ as a prefix. Returns the SHA1 of the branch or tag if found. z origin/%sz5Could not find a tag or branch '%s', assuming commit.N)Úget_refsrÚwarn)r r7ÚdestÚ rev_optionsÚ revisionsÚ origin_revr-r-r.Úcheck_rev_optionsAs     zGit.check_rev_optionscCsPt|jdd|gd|ƒt|jddg|d|ƒ|j|ƒdS)NÚconfigzremote.origin.urlr>Úcheckoutz-q)rrBÚupdate_submodules)r rIr!rJr-r-r.ÚswitchSs z Git.switchcCsrt|jddgd|ƒ|r>|j|d||ƒ}nt|jdddg|d|ƒ|j|ƒdS)NÚfetchz-qr>rÚresetz--hard)rrBrMrP)r rIrJr-r-r.Úupdate[s #z Git.updatecCs|jƒ\}}|r.|g}d|}ndg}d}|j||||ƒrþtjd||t|ƒfƒt|jdd||gƒ|j|ƒ|rþ|j|||ƒ}|j |ƒj |dƒsût|jddg|d |ƒqûqþndS) Nz (to %s)z origin/masterÚzCloning %s%s to %sr z-qrrOr>) Ú get_url_revÚcheck_destinationrÚnotifyrrrBrPrMÚ get_revisionr2)r rIr!r7rJÚ rev_displayr-r-r.Úobtaines     z Git.obtaincCs.t|jddgddd|ƒ}|jƒS)NrNzremote.origin.urlr=Fr>)rrBr1)r rDr!r-r-r.Úget_urlxsz Git.get_urlcCs.t|jddgddd|ƒ}|jƒS)Nz rev-parseÚHEADr=Fr>)rrBr1)r rDÚ current_revr-r-r.rY~s!zGit.get_revisioncCs t|jdgddd|ƒ}i}xÛ|jƒjƒD]Ç}|jddƒ\}}|jƒ}d}|jdƒr’|tdƒd…}nP|jd ƒrº|td ƒd…}n(|jd ƒrâ|td ƒd…}n|dk r:|jƒ||ú rNz refs/remotes/z refs/heads/z refs/tags/)rrBr1r0Úsplitr2r)r rDÚoutputÚrvr8ÚcommitÚrefÚref_namer-r-r.rGƒs   z Git.get_refsc CsÒ|j|ƒ}|jƒjdƒs1d|}n|jƒjddƒd}|sWdS|j|ƒ}|j|ƒ}tdd„|jƒDƒƒ}||kr·d|||f} n d |} d ||| fS) Nzgit:zgit+ú-rrcss!|]\}}||fVqdS)Nr-)Ú.0rdrcr-r-r.ú ¡sz*Git.get_src_requirement..z%s-%sz%s-devz %s@%s#egg=%s) r\Úlowerr2Úegg_namer`rYrGÚdictÚitems) r ÚdistrDÚ find_tagsÚrepoÚegg_project_namer^ÚrefsÚnames_by_commitÚ full_egg_namer-r-r.Úget_src_requirement–s   zGit.get_src_requirementcs‘d|jkrld|jks$t‚|jjddƒ|_tt|ƒjƒ\}}|jddƒ}ntt|ƒjƒ\}}||fS)a; Prefixes stub URLs like 'user@hostname:user/repo.git' with 'ssh://'. That's required because although they use SSH they sometimes doesn'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. z://zfile:zgit+z git+ssh://zssh://rU)r!ÚAssertionErrorrrr rV)r r!r7)r,r-r.rV«szGit.get_url_revcCsNtjjtjj|dƒƒs%dSt|jdddddgd|ƒdS)Nz .gitmodulesÚ submodulerTz--initz --recursivez-qr>)Úosr&ÚexistsÚjoinrrB)r rDr-r-r.rP¼s!zGit.update_submodules)zgitr rrrr)Ú__name__Ú __module__Ú __qualname__ÚnameÚdirnameÚ repo_nameÚschemesÚ bundle_fileÚguiderr;rFrMrQrTr[r\rYrGrtrVrPr-r-)r,r.r s&         r )r?r3Úos.pathrwÚpip.utilrrrÚpip.vcsrrÚpip.logrZpip.backwardcompatrr rrr Úregisterr-r-r-r.Ús     µ