diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-28 12:00:58 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-28 12:00:58 +0100 |
commit | 146a6fe18da94e12aa46ec74582db640e3bbb3a9 (patch) | |
tree | 8c26d4903de1002acb40ec5cead52e30363a95b5 | |
parent | 87afd252bd11026b6ba3db8525f949cfb62c90fc (diff) | |
download | gitpython-146a6fe18da94e12aa46ec74582db640e3bbb3a9.tar.gz |
IterableList: added support for prefix allowing remote.refs.master constructs, previously it was remote.refs['%s/master'%remote]
Added first simple test for push support, which shows that much more work is needed on that side to allow just-in-time progress information
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | lib/git/remote.py | 19 | ||||
-rw-r--r-- | lib/git/utils.py | 17 | ||||
-rw-r--r-- | test/git/test_remote.py | 24 |
4 files changed, 53 insertions, 12 deletions
@@ -117,6 +117,11 @@ Repo currently regex are used a lot although we can deduct what will be next. - Read data from a stream directly from git command * Figure out how to implement a proper merge API +* There should be a way to create refs and delete them, instead of having to use + the awkward Head.create( repo, ... ) way +* repo.checkout should be added that does everything HEAD.reset does, but in addition + it allows to checkout heads beforehand, hence its more like a repo.head.reference = other_head. + Submodules ---------- 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): """ diff --git a/test/git/test_remote.py b/test/git/test_remote.py index 6870e0e5..37ba71f9 100644 --- a/test/git/test_remote.py +++ b/test/git/test_remote.py @@ -23,7 +23,7 @@ class TestRemote(TestBase): for info in results: if isinstance(info.ref, Reference): assert info.flags != 0 - # END referebce type flags handling + # END reference type flags handling assert isinstance(info.ref, (SymbolicReference, Reference)) if info.flags & info.FORCED_UPDATE: assert isinstance(info.commit_before_forced_update, Commit) @@ -122,8 +122,26 @@ class TestRemote(TestBase): res = fetch_and_test(remote, tags=True) self.failUnlessRaises(IndexError, get_info, res, remote, str(rtag)) + def _test_push_and_pull(self,remote, rw_repo, remote_repo): + # push our changes + lhead = rw_repo.head + lindex = rw_repo.index + # assure we are on master and it is checked out where the remote is + lhead.reference = rw_repo.heads.master + lhead.reset(remote.refs.master, working_tree=True) + + # push without spec should fail ( without further configuration ) + # self.failUnlessRaises(GitCommandError, remote.push) + + new_file = self._make_file("new_file", "hello world", rw_repo) + lindex.add([new_file]) + lindex.commit("test commit") + remote.push(lhead.reference) + + self.fail("test --all") + self.fail("test rewind and force -push") + self.fail("test general fail due to invalid refspec") - def _test_pull(self,remote, rw_repo, remote_repo): # pull is essentially a fetch + merge, hence we just do a light # test here, leave the reset to the actual merge testing # fails as we did not specify a branch and there is no configuration for it @@ -184,7 +202,7 @@ class TestRemote(TestBase): self._test_fetch(remote, rw_repo, remote_repo) # PULL TESTING - self._test_pull(remote, rw_repo, remote_repo) + self._test_push_and_pull(remote, rw_repo, remote_repo) remote.update() # END for each remote |