From 737dfbfc71490b41ab92c6d49b0c303c0e197f46 Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Tue, 3 Apr 2018 14:46:33 -0500 Subject: [PATCH] Conditionally fetch the revision if it's a ref --- src/pip/_internal/vcs/git.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pip/_internal/vcs/git.py b/src/pip/_internal/vcs/git.py index 3528d8fd9..33c68068f 100644 --- a/src/pip/_internal/vcs/git.py +++ b/src/pip/_internal/vcs/git.py @@ -191,12 +191,16 @@ class Git(VersionControl): # Only do a checkout if the current commit id doesn't match # the requested revision. if not self.is_commit_id_equal(dest, rev_options.rev): - cmd_args = ['fetch', '-q', url] + rev_options.to_args() - self.run_command(cmd_args, cwd=dest) - self.run_command( - ['checkout', '-q', 'FETCH_HEAD'], - cwd=dest, - ) + rev = rev_options.rev + # Only fetch the revision if it's a ref + if rev.startswith('refs/'): + self.run_command( + ['fetch', '-q', url] + rev_options.to_args(), + cwd=dest, + ) + # Change the revision to the SHA of the ref we fetched + rev = 'FETCH_HEAD' + self.run_command(['checkout', '-q', rev], cwd=dest) #: repo may contain submodules self.update_submodules(dest) -- GitLab