Skip to content

Commit b206ac7

Browse files
committed
Be extra safe in caching Git urls
Do not cache in case a branch/tag has the same name as a commit sha.
1 parent 9086820 commit b206ac7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/pip/_internal/vcs/git.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,17 @@ def is_immutable_rev_checkout(self, url, dest):
6464
_, rev_options = self.get_url_rev_options(hide_url(url))
6565
if not rev_options.rev:
6666
return False
67-
return self.is_commit_id_equal(dest, rev_options.rev)
67+
if not self.is_commit_id_equal(dest, rev_options.rev):
68+
# the current commit is different from rev,
69+
# which means rev was something else than a commit hash
70+
return False
71+
# return False in the rare case rev is both a commit hash
72+
# and a tag or a branch; we don't want to cache in that case
73+
# because that branch/tag could point to something else in the future
74+
is_tag_or_branch = bool(
75+
self.get_revision_sha(dest, rev_options.rev)[0]
76+
)
77+
return not is_tag_or_branch
6878

6979
def get_git_version(self):
7080
VERSION_PFX = 'git version '

0 commit comments

Comments
 (0)