Skip to content

Commit 3236f8b

Browse files
committed
stale_refs() may now also handle other kinds of references, like tags.
Fixes #260
1 parent e0acb83 commit 3236f8b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

git/remote.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -455,16 +455,28 @@ def stale_refs(self):
455455
remote side, but are still available locally.
456456
457457
The IterableList is prefixed, hence the 'origin' must be omitted. See
458-
'refs' property for an example."""
458+
'refs' property for an example.
459+
460+
To make things more complicated, it can be possble for the list to include
461+
other kinds of references, for example, tag references, if these are stale
462+
as well. This is a fix for the issue described here:
463+
https://github.com/gitpython-developers/GitPython/issues/260
464+
"""
459465
out_refs = IterableList(RemoteReference._id_attribute_, "%s/" % self.name)
460466
for line in self.repo.git.remote("prune", "--dry-run", self).splitlines()[2:]:
461467
# expecting
462468
# * [would prune] origin/new_branch
463469
token = " * [would prune] "
464470
if not line.startswith(token):
465471
raise ValueError("Could not parse git-remote prune result: %r" % line)
466-
fqhn = "%s/%s" % (RemoteReference._common_path_default, line.replace(token, ""))
467-
out_refs.append(RemoteReference(self.repo, fqhn))
472+
ref_name = line.replace(token, "")
473+
# sometimes, paths start with a full ref name, like refs/tags/foo, see #260
474+
if ref_name.startswith(Reference._common_path_default + '/'):
475+
out_refs.append(SymbolicReference.from_path(self.repo, ref_name))
476+
else:
477+
fqhn = "%s/%s" % (RemoteReference._common_path_default, ref_name)
478+
out_refs.append(RemoteReference(self.repo, fqhn))
479+
# end special case handlin
468480
# END for each line
469481
return out_refs
470482

0 commit comments

Comments
 (0)