Skip to content

Commit

Permalink
Be extra safe in caching Git urls
Browse files Browse the repository at this point in the history
Do not cache in case a branch/tag has the
same name as a commit sha.
  • Loading branch information
sbidoul committed Nov 2, 2019
1 parent 696f484 commit 8160664
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/pip/_internal/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,17 @@ def is_immutable_rev_checkout(self, url, dest):
_, rev_options = self.get_url_rev_options(hide_url(url))
if not rev_options.rev:
return False
return self.is_commit_id_equal(dest, rev_options.rev)
if not self.is_commit_id_equal(dest, rev_options.rev):
# the current commit is different from rev,
# which means rev was something else than a commit hash
return False
# return False in the rare case rev is both a commit hash
# and a tag or a branch; we don't want to cache in that case
# because that branch/tag could point to something else in the future
is_tag_or_branch = bool(
self.get_revision_sha(dest, rev_options.rev)[0]
)
return not is_tag_or_branch

def get_git_version(self):
VERSION_PFX = 'git version '
Expand Down

0 comments on commit 8160664

Please sign in to comment.