diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-28 22:17:39 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-28 22:17:39 +0100 |
commit | 8b5121414aaf2648b0e809e926d1016249c0222c (patch) | |
tree | e41495ec396a8259c30302e0a1aa7489f607b2d1 /test/git/test_remote.py | |
parent | 685d6e651197d54e9a3e36f5adbadd4d21f4c7e5 (diff) | |
download | gitpython-8b5121414aaf2648b0e809e926d1016249c0222c.tar.gz |
Another attempt to make fetch emit progress information, but in fact its proven now that this is not happening if stderr is being redirected. A test is in place that will most likely fail in case this ever changes
Diffstat (limited to 'test/git/test_remote.py')
-rw-r--r-- | test/git/test_remote.py | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/test/git/test_remote.py b/test/git/test_remote.py index 99f64756..e4ad5638 100644 --- a/test/git/test_remote.py +++ b/test/git/test_remote.py @@ -9,6 +9,10 @@ from git import * import tempfile import shutil import os +import random + +# assure we have repeatable results +random.seed(0) class TestRemote(TestBase): @@ -37,6 +41,15 @@ class TestRemote(TestBase): self.failUnlessRaises(ValueError, FetchInfo._from_line, repo, "nonsense", '') self.failUnlessRaises(ValueError, FetchInfo._from_line, repo, "? [up to date] 0.1.7RC -> origin/0.1.7RC", '') + def _commit_random_file(self, repo): + #Create a file with a random name and random data and commit it to repo. + # Return the commited absolute file path + index = repo.index + new_file = self._make_file(os.path.basename(tempfile.mktemp()),str(random.random()), repo) + index.add([new_file]) + index.commit("Committing %s" % new_file) + return new_file + def _test_fetch(self,remote, rw_repo, remote_repo): # specialized fetch testing to de-clutter the main test self._test_fetch_info(rw_repo) @@ -124,20 +137,39 @@ class TestRemote(TestBase): self.failUnlessRaises(IndexError, get_info, res, remote, str(rtag)) # provoke to receive actual objects to see what kind of output we have to - # expect. Previously we did not really receive new objects - # This will only work for true remote repositories, not for local ones ! - if not remote.config_reader.get('url').startswith("git://"): - return - - shallow_repo_dir = tempfile.mktemp("shallow_repo") - shallow_repo = remote_repo.clone(shallow_repo_dir, depth=1, shared=False) + # expect. For that we need a remote transport protocol + # Create a new UN-shared repo and fetch into it after we pushed a change + # to the shared repo + other_repo_dir = tempfile.mktemp("other_repo") + # must clone with a local path for the repo implementation not to freak out + # as it wants local paths only ( which I can understand ) + other_repo = remote_repo.clone(other_repo_dir, shared=False) + remote_repo_url = "git://localhost%s"%remote_repo.path + + # put origin to git-url + other_origin = other_repo.remotes.origin + other_origin.config_writer.set("url", remote_repo_url) + # it automatically creates alternates as remote_repo is shared as well. + # It will use the transport though and ignore alternates when fetching + # assert not other_repo.alternates # this would fail + + # assure we are in the right state + rw_repo.head.reset(remote.refs.master, working_tree=True) try: - res = shallow_repo.remotes.origin.fetch(depth=10) + self._commit_random_file(rw_repo) + remote.push(rw_repo.head.reference) + + # here I would expect to see remote-information about packing + # objects and so on. Unfortunately, this does not happen + # if we are redirecting the output - git explicitly checks for this + # and only provides progress information to ttys + res = fetch_and_test(other_origin) finally: - shutil.rmtree(shallow_repo_dir) + shutil.rmtree(other_repo_dir) # END test and cleanup def _test_push_and_pull(self,remote, rw_repo, remote_repo): + return # push our changes lhead = rw_repo.head lindex = rw_repo.index @@ -146,11 +178,10 @@ class TestRemote(TestBase): lhead.reset(remote.refs.master, working_tree=True) # push without spec should fail ( without further configuration ) + # well, works # self.failUnlessRaises(GitCommandError, remote.push) - new_file = self._make_file("new_file", "hello world", rw_repo) - lindex.add([new_file]) - lindex.commit("test commit") + self._commit_random_file(rw_repo) remote.push(lhead.reference) self.fail("test --all") @@ -167,6 +198,7 @@ class TestRemote(TestBase): def test_base(self, rw_repo, remote_repo): num_remotes = 0 remote_set = set() + ran_fetch_test = False for remote in rw_repo.remotes: num_remotes += 1 @@ -215,7 +247,12 @@ class TestRemote(TestBase): # END for each rename ( back to prev_name ) # FETCH TESTING - self._test_fetch(remote, rw_repo, remote_repo) + # Only for remotes - local cases are the same or less complicated + # as additional progress information will never be emitted + if remote.name == "daemon_origin": + self._test_fetch(remote, rw_repo, remote_repo) + ran_fetch_test = True + # END fetch test # PULL TESTING self._test_push_and_pull(remote, rw_repo, remote_repo) @@ -223,6 +260,7 @@ class TestRemote(TestBase): remote.update() # END for each remote + assert ran_fetch_test assert num_remotes assert num_remotes == len(remote_set) |