diff options
Diffstat (limited to 'lib/git')
-rw-r--r-- | lib/git/remote.py | 19 | ||||
-rw-r--r-- | lib/git/utils.py | 17 |
2 files changed, 27 insertions, 9 deletions
diff --git a/lib/git/remote.py b/lib/git/remote.py index 02a955b0..47743913 100644 --- a/lib/git/remote.py +++ b/lib/git/remote.py @@ -256,9 +256,11 @@ class Remote(LazyMixin, Iterable): def refs(self): """ Returns - IterableList of RemoteReference objects + IterableList of RemoteReference objects. It is prefixed, allowing + you to omit the remote path portion, i.e.:: + remote.refs.master # yields RemoteReference('/refs/remotes/origin/master') """ - out_refs = IterableList(RemoteReference._id_attribute_) + out_refs = IterableList(RemoteReference._id_attribute_, "%s/" % self.name) for ref in RemoteReference.list_items(self.repo): if ref.remote_name == self.name: out_refs.append(ref) @@ -274,8 +276,11 @@ class Remote(LazyMixin, Iterable): IterableList RemoteReference objects that do not have a corresponding head in the remote reference anymore as they have been deleted on the remote side, but are still available locally. + + The IterableList is prefixed, hence the 'origin' must be omitted. See + 'refs' property for an example. """ - out_refs = IterableList(RemoteReference._id_attribute_) + out_refs = IterableList(RemoteReference._id_attribute_, "%s/" % self.name) for line in self.repo.git.remote("prune", "--dry-run", self).splitlines()[2:]: # expecting # * [would prune] origin/new_branch @@ -357,7 +362,6 @@ class Remote(LazyMixin, Iterable): def _get_fetch_info_from_stderr(self, stderr): # skip first line as it is some remote info we are not interested in - print stderr output = IterableList('name') err_info = stderr.splitlines()[1:] @@ -426,7 +430,12 @@ class Remote(LazyMixin, Iterable): Returns self """ - self.repo.git.push(self, refspec, **kwargs) + proc = self.repo.git.push(self, refspec, porcelain=True, as_process=True, **kwargs) + print "stdout"*10 + print proc.stdout.read() + print "stderr"*10 + print proc.stderr.read() + proc.wait() return self @property diff --git a/lib/git/utils.py b/lib/git/utils.py index 8cdb4804..48427ff2 100644 --- a/lib/git/utils.py +++ b/lib/git/utils.py @@ -260,16 +260,25 @@ class IterableList(list): heads.master heads['master'] heads[0] + + It requires an id_attribute name to be set which will be queried from its + contained items to have a means for comparison. + + A prefix can be specified which is to be used in case the id returned by the + items always contains a prefix that does not matter to the user, so it + can be left out. """ - __slots__ = '_id_attr' + __slots__ = ('_id_attr', '_prefix') - def __new__(cls, id_attr): + def __new__(cls, id_attr, prefix=''): return super(IterableList,cls).__new__(cls) - def __init__(self, id_attr): + def __init__(self, id_attr, prefix=''): self._id_attr = id_attr + self._prefix = prefix def __getattr__(self, attr): + attr = self._prefix + attr for item in self: if getattr(item, self._id_attr) == attr: return item @@ -283,7 +292,7 @@ class IterableList(list): try: return getattr(self, index) except AttributeError: - raise IndexError( "No item found with id %r" % index ) + raise IndexError( "No item found with id %r" % self._prefix + index ) class Iterable(object): """ |