3

Q'íc½+ã@s´ddlmZddlZddlZddlZddlmZddlm	Z	ddl
mZddl
m
ZddlmZddlmZmZddlmZmZejZejZejeƒZGd	d
„d
eƒZejeƒdS)é)Úabsolute_importN)Úsamefile)Ú
BadCommand)Úparse)Úrequest)Údisplay_pathÚrmtree)ÚvcsÚVersionControlcsâeZdZdZdZdZd6Zd7‡fd
d„	Zdd
„Zdd„Z	dd„Z
dd„Zdd„Zdd„Z
dd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Z‡fd0d1„Zd2d3„Ze‡fd4d5„ƒZ‡ZS)8ÚGitÚgitz.gitÚcloneúgit+httpú	git+httpsúgit+sshúgit+gitúgit+fileNcs¶|ršt|ƒ\}}}}}|jdƒrš|dt|jdƒƒ…}	|	tj|ƒjddƒjdƒ}
t|||
||fƒ}|jdƒd}|d|…t||d…||
||fƒ}t	t
|ƒj|f|ž|ŽdS)NÚfileú/ú\ú+é)ÚurlsplitÚendswithÚlenÚlstripÚurllib_requestÚurl2pathnameÚreplaceÚ
urlunsplitÚfindÚsuperrÚ__init__)ÚselfÚurlÚargsÚkwargsÚschemeÚnetlocÚpathÚqueryÚfragmentÚinitial_slashesÚnewpathÚ
after_plus)Ú	__class__©ú*/tmp/pip-build-l_bcah40/pip/pip/vcs/git.pyr" s

zGit.__init__cCsTd}|jdgdd}|j|ƒr0|t|ƒd…}nd}dj|jdƒdd…ƒ}t|ƒS)Nzgit version ÚversionF)Úshow_stdoutÚÚ.é)Úrun_commandÚ
startswithrÚjoinÚsplitÚ
parse_version)r#ÚVERSION_PFXr2r0r0r1Úget_git_version5s
zGit.get_git_versioncCsVtjddƒ}|j|ƒz0|jdƒs*|d}|jdddd|gd|d	Wd
t|ƒXd
S)z@Export the Git repository at the url to the destination locationz-exportzpip-rzcheckout-indexz-az-fz--prefixF)r3ÚcwdN)ÚtempfileÚmkdtempÚunpackrr7r)r#ÚlocationÚtemp_dirr0r0r1ÚexportBs

z
Git.exportcCsJ|j|ƒ}d|}||kr$||gS||kr6||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_short_refsÚloggerÚwarning)r#ÚrevÚdestÚrev_optionsÚ	revisionsÚ
origin_revr0r0r1Úcheck_rev_optionsOs


zGit.check_rev_optionscCs|j|ƒj|dƒS)a

        Compare the current sha to the ref. ref may be a branch or tag name,
        but current rev will always point to a sha. This means that a branch
        or tag will never compare as True. So this ultimately only matches
        against exact shas.
        r)Úget_revisionr8)r#rIrJr0r0r1Ú
check_versioncszGit.check_versioncCs8|jdd|g|d|jddg||d|j|ƒdS)NÚconfigzremote.origin.url)r>Úcheckoutz-q)r7Úupdate_submodules)r#rIr$rJr0r0r1Úswitchlsz
Git.switchcCst|jƒtdƒkr&|jdddg|dn|jddg|d|rN|j|d||ƒ}|jdddg||d|j|ƒdS)	Nz1.9.0Úfetchz-qz--tags)r>rÚresetz--hard)r=r;r7rMrR)r#rIrJr0r0r1Úupdatersz
Git.updatecCs¢|jƒ\}}|r |g}d|}n
dg}d}|j||||ƒržtjd||t|ƒƒ|jdd||gƒ|r”|j|||ƒ}|j||ƒs”|jddg||d|j|ƒdS)	Nz (to %s)z
origin/masterr4zCloning %s%s to %sr
z-qrQ)r>)	Úget_url_revÚcheck_destinationrFÚinforr7rMrOrR)r#rIr$rHrJÚrev_displayr0r0r1Úobtain‚s"

z
Git.obtaincCsZ|jdddgd|d}|jƒ}|d}x|D]}|jdƒr,|}Pq,W|jdƒd	}|jƒS)
z+Return URL of the first remote encountered.rPz--get-regexpzremote\..*\.urlF)r3r>rzremote.origin.url ú r)r7Ú
splitlinesr8r:Ústrip)r#rBÚremotesÚfound_remoteÚremoter$r0r0r1Úget_url›s


zGit.get_urlcCs|jddgd|d}|jƒS)Nz	rev-parseÚHEADF)r3r>)r7r^)r#rBÚcurrent_revr0r0r1rN©szGit.get_revisionccsN|jdgd|d}x6|jƒjƒD]&}|jddƒ\}}|jƒ|jƒfVq WdS)z4Yields tuples of (commit, ref) for branches and tagszshow-refF)r3r>r\rN)r7r^r]r:)r#rBÚoutputÚlineÚcommitÚrefr0r0r1Ú
get_full_refs®s

zGit.get_full_refscCs
|jdƒS)Nz
refs/remotes/)r8)r#rhr0r0r1Ú
is_ref_remote¶szGit.is_ref_remotecCs
|jdƒS)Nzrefs/heads/)r8)r#rhr0r0r1Ú
is_ref_branch¹szGit.is_ref_branchcCs
|jdƒS)Nz
refs/tags/)r8)r#rhr0r0r1Ú
is_ref_tag¼szGit.is_ref_tagcCs"t|j|ƒ|j|ƒ|j|ƒfƒS)z0A ref is a commit sha if it is not anything else)Úanyrjrkrl)r#rhr0r0r1Ú
is_ref_commit¿szGit.is_ref_commitcCs
|j|ƒS)N)rE)r#rBr0r0r1Úget_refsÈszGit.get_refscCs†i}x||j|ƒD]n\}}d}|j|ƒr8|tdƒd…}n6|j|ƒrT|tdƒd…}n|j|ƒrn|tdƒd…}|dk	r|||<qW|S)z=Return map of named refs (branches or tags) to commit hashes.Nz
refs/remotes/zrefs/heads/z
refs/tags/)rirjrrkrl)r#rBÚrvrgrhÚref_namer0r0r1rEËs


zGit.get_short_refscCs¤|jddgd|djƒ}tjj|ƒs2tjj||ƒ}tjj|dƒ}|}xBtjjtjj|dƒƒs†|}tjj|ƒ}||krFtj	d|ƒdSqFWt
||ƒr–dStjj||ƒS)	z:Return the relative path of setup.py to the git repo root.z	rev-parsez	--git-dirF)r3r>z..zsetup.pyzGCould not find setup.py for directory %s (tried all parent directories)N)r7r^Úosr)Úisabsr9ÚexistsÚdirnamerFrGrÚrelpath)r#rBÚgit_dirÚroot_dirÚ
orig_locationÚ
last_locationr0r0r1Ú_get_subdirectoryÚs"

zGit._get_subdirectorycCsr|j|ƒ}|jƒjdƒs d|}|jƒjddƒd}|s<dS|j|ƒ}d|||f}|j|ƒ}|rn|d|7}|S)Nzgit:zgit+ú-rrz%s@%s#egg=%sz&subdirectory=)rbÚlowerr8Úegg_namer:rNr{)r#ÚdistrBÚrepoÚegg_project_namerdÚreqÚsubdirectoryr0r0r1Úget_src_requirementõs


zGit.get_src_requirementcsbd|jkrHd|jkst‚|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://r4)r$ÚAssertionErrorrr!rrW)r#r$rH)r/r0r1rWs
zGit.get_url_revcCs6tjjtjj|dƒƒsdS|jdddddg|ddS)Nz.gitmodulesÚ	submodulerVz--initz--recursivez-q)r>)rrr)rtr9r7)r#rBr0r0r1rRs
zGit.update_submodulescsVtt|ƒj|ƒrdSy|ƒjdg|ddd}|Stk
rPtjd|ƒdSXdS)NTz	rev-parseFÚignore)r>r3Ú
on_returncodezKcould not determine if %s is under git control because git is not available)r!rÚcontrols_locationr7rrFÚdebug)ÚclsrBÚr)r/r0r1r‰s
zGit.controls_location)rrrrrr)N)Ú__name__Ú
__module__Ú__qualname__ÚnameruÚ	repo_nameÚschemesr"r=rDrMrOrSrVr[rbrNrirjrkrlrnrorEr{r„rWrRÚclassmethodr‰Ú
__classcell__r0r0)r/r1rs4

		r)Ú
__future__rÚloggingr?Úos.pathrrÚ
pip.compatrÚpip.exceptionsrZpip._vendor.six.moves.urllibrÚurllib_parserrZpip._vendor.packaging.versionr;Ú	pip.utilsrrÚpip.vcsr	r
rrÚ	getLoggerrrFrÚregisterr0r0r0r1Ú<module>s"