|
|
6c9912 |
Backport of https://github.com/pypa/pip/pull/9827 with parts of
|
|
|
6c9912 |
https://github.com/pypa/pip/pull/4690 to make it work with pip v9.0.1
|
|
|
6c9912 |
diff --git a/pip/vcs/git.py b/pip/vcs/git.py
|
|
|
6c9912 |
index 2187dd8..d1502f8 100644
|
|
|
6c9912 |
--- a/pip/vcs/git.py
|
|
|
6c9912 |
+++ b/pip/vcs/git.py
|
|
|
6c9912 |
@@ -81,7 +81,7 @@ class Git(VersionControl):
|
|
|
6c9912 |
and branches may need origin/ as a prefix.
|
|
|
6c9912 |
Returns the SHA1 of the branch or tag if found.
|
|
|
6c9912 |
"""
|
|
|
6c9912 |
- revisions = self.get_short_refs(dest)
|
|
|
6c9912 |
+ revisions = self.get_short_refs(dest, rev)
|
|
|
6c9912 |
|
|
|
6c9912 |
origin_rev = 'origin/%s' % rev
|
|
|
6c9912 |
if origin_rev in revisions:
|
|
|
6c9912 |
@@ -171,12 +171,20 @@ class Git(VersionControl):
|
|
|
6c9912 |
['rev-parse', 'HEAD'], show_stdout=False, cwd=location)
|
|
|
6c9912 |
return current_rev.strip()
|
|
|
6c9912 |
|
|
|
6c9912 |
- def get_full_refs(self, location):
|
|
|
6c9912 |
+ def get_full_refs(self, location, pattern=''):
|
|
|
6c9912 |
"""Yields tuples of (commit, ref) for branches and tags"""
|
|
|
6c9912 |
- output = self.run_command(['show-ref'],
|
|
|
6c9912 |
+ output = self.run_command(['show-ref', pattern],
|
|
|
6c9912 |
show_stdout=False, cwd=location)
|
|
|
6c9912 |
- for line in output.strip().splitlines():
|
|
|
6c9912 |
- commit, ref = line.split(' ', 1)
|
|
|
6c9912 |
+ for line in output.split("\n"):
|
|
|
6c9912 |
+ line = line.rstrip("\r")
|
|
|
6c9912 |
+ if not line:
|
|
|
6c9912 |
+ continue
|
|
|
6c9912 |
+ try:
|
|
|
6c9912 |
+ commit, ref = line.split(' ', 1)
|
|
|
6c9912 |
+ except ValueError:
|
|
|
6c9912 |
+ # Include the offending line to simplify troubleshooting if
|
|
|
6c9912 |
+ # this error ever occurs.
|
|
|
6c9912 |
+ raise ValueError(f'unexpected show-ref line: {line!r}')
|
|
|
6c9912 |
yield commit.strip(), ref.strip()
|
|
|
6c9912 |
|
|
|
6c9912 |
def is_ref_remote(self, ref):
|
|
|
6c9912 |
@@ -200,10 +208,10 @@ class Git(VersionControl):
|
|
|
6c9912 |
def get_refs(self, location):
|
|
|
6c9912 |
return self.get_short_refs(location)
|
|
|
6c9912 |
|
|
|
6c9912 |
- def get_short_refs(self, location):
|
|
|
6c9912 |
+ def get_short_refs(self, location, pattern=''):
|
|
|
6c9912 |
"""Return map of named refs (branches or tags) to commit hashes."""
|
|
|
6c9912 |
rv = {}
|
|
|
6c9912 |
- for commit, ref in self.get_full_refs(location):
|
|
|
6c9912 |
+ for commit, ref in self.get_full_refs(location, pattern):
|
|
|
6c9912 |
ref_name = None
|
|
|
6c9912 |
if self.is_ref_remote(ref):
|
|
|
6c9912 |
ref_name = ref[len('refs/remotes/'):]
|