You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6KB

  1. import os
  2. from git.util import join_path
  3. import os.path as osp
  4. from .head import Head
  5. __all__ = ["RemoteReference"]
  6. class RemoteReference(Head):
  7. """Represents a reference pointing to a remote head."""
  8. _common_path_default = Head._remote_common_path_default
  9. @classmethod
  10. def iter_items(cls, repo, common_path=None, remote=None):
  11. """Iterate remote references, and if given, constrain them to the given remote"""
  12. common_path = common_path or cls._common_path_default
  13. if remote is not None:
  14. common_path = join_path(common_path, str(remote))
  15. # END handle remote constraint
  16. return super(RemoteReference, cls).iter_items(repo, common_path)
  17. @classmethod
  18. def delete(cls, repo, *refs, **kwargs):
  19. """Delete the given remote references
  20. :note:
  21. kwargs are given for comparability with the base class method as we
  22. should not narrow the signature."""
  23. repo.git.branch("-d", "-r", *refs)
  24. # the official deletion method will ignore remote symbolic refs - these
  25. # are generally ignored in the refs/ folder. We don't though
  26. # and delete remainders manually
  27. for ref in refs:
  28. try:
  29. os.remove(osp.join(repo.common_dir, ref.path))
  30. except OSError:
  31. pass
  32. try:
  33. os.remove(osp.join(repo.git_dir, ref.path))
  34. except OSError:
  35. pass
  36. # END for each ref
  37. @classmethod
  38. def create(cls, *args, **kwargs):
  39. """Used to disable this method"""
  40. raise TypeError("Cannot explicitly create remote references")