99import tempfile
1010import shutil
1111import os
12+ import random
13+
14+ # assure we have repeatable results
15+ random .seed (0 )
1216
1317class TestRemote (TestBase ):
1418
@@ -37,6 +41,15 @@ def _test_fetch_info(self, repo):
3741 self .failUnlessRaises (ValueError , FetchInfo ._from_line , repo , "nonsense" , '' )
3842 self .failUnlessRaises (ValueError , FetchInfo ._from_line , repo , "? [up to date] 0.1.7RC -> origin/0.1.7RC" , '' )
3943
44+ def _commit_random_file (self , repo ):
45+ #Create a file with a random name and random data and commit it to repo.
46+ # Return the commited absolute file path
47+ index = repo .index
48+ new_file = self ._make_file (os .path .basename (tempfile .mktemp ()),str (random .random ()), repo )
49+ index .add ([new_file ])
50+ index .commit ("Committing %s" % new_file )
51+ return new_file
52+
4053 def _test_fetch (self ,remote , rw_repo , remote_repo ):
4154 # specialized fetch testing to de-clutter the main test
4255 self ._test_fetch_info (rw_repo )
@@ -124,20 +137,39 @@ def get_info(res, remote, name):
124137 self .failUnlessRaises (IndexError , get_info , res , remote , str (rtag ))
125138
126139 # provoke to receive actual objects to see what kind of output we have to
127- # expect. Previously we did not really receive new objects
128- # This will only work for true remote repositories, not for local ones !
129- if not remote .config_reader .get ('url' ).startswith ("git://" ):
130- return
131-
132- shallow_repo_dir = tempfile .mktemp ("shallow_repo" )
133- shallow_repo = remote_repo .clone (shallow_repo_dir , depth = 1 , shared = False )
140+ # expect. For that we need a remote transport protocol
141+ # Create a new UN-shared repo and fetch into it after we pushed a change
142+ # to the shared repo
143+ other_repo_dir = tempfile .mktemp ("other_repo" )
144+ # must clone with a local path for the repo implementation not to freak out
145+ # as it wants local paths only ( which I can understand )
146+ other_repo = remote_repo .clone (other_repo_dir , shared = False )
147+ remote_repo_url = "git://localhost%s" % remote_repo .path
148+
149+ # put origin to git-url
150+ other_origin = other_repo .remotes .origin
151+ other_origin .config_writer .set ("url" , remote_repo_url )
152+ # it automatically creates alternates as remote_repo is shared as well.
153+ # It will use the transport though and ignore alternates when fetching
154+ # assert not other_repo.alternates # this would fail
155+
156+ # assure we are in the right state
157+ rw_repo .head .reset (remote .refs .master , working_tree = True )
134158 try :
135- res = shallow_repo .remotes .origin .fetch (depth = 10 )
159+ self ._commit_random_file (rw_repo )
160+ remote .push (rw_repo .head .reference )
161+
162+ # here I would expect to see remote-information about packing
163+ # objects and so on. Unfortunately, this does not happen
164+ # if we are redirecting the output - git explicitly checks for this
165+ # and only provides progress information to ttys
166+ res = fetch_and_test (other_origin )
136167 finally :
137- shutil .rmtree (shallow_repo_dir )
168+ shutil .rmtree (other_repo_dir )
138169 # END test and cleanup
139170
140171 def _test_push_and_pull (self ,remote , rw_repo , remote_repo ):
172+ return
141173 # push our changes
142174 lhead = rw_repo .head
143175 lindex = rw_repo .index
@@ -146,11 +178,10 @@ def _test_push_and_pull(self,remote, rw_repo, remote_repo):
146178 lhead .reset (remote .refs .master , working_tree = True )
147179
148180 # push without spec should fail ( without further configuration )
181+ # well, works
149182 # self.failUnlessRaises(GitCommandError, remote.push)
150183
151- new_file = self ._make_file ("new_file" , "hello world" , rw_repo )
152- lindex .add ([new_file ])
153- lindex .commit ("test commit" )
184+ self ._commit_random_file (rw_repo )
154185 remote .push (lhead .reference )
155186
156187 self .fail ("test --all" )
@@ -167,6 +198,7 @@ def _test_push_and_pull(self,remote, rw_repo, remote_repo):
167198 def test_base (self , rw_repo , remote_repo ):
168199 num_remotes = 0
169200 remote_set = set ()
201+ ran_fetch_test = False
170202
171203 for remote in rw_repo .remotes :
172204 num_remotes += 1
@@ -215,14 +247,20 @@ def test_base(self, rw_repo, remote_repo):
215247 # END for each rename ( back to prev_name )
216248
217249 # FETCH TESTING
218- self ._test_fetch (remote , rw_repo , remote_repo )
250+ # Only for remotes - local cases are the same or less complicated
251+ # as additional progress information will never be emitted
252+ if remote .name == "daemon_origin" :
253+ self ._test_fetch (remote , rw_repo , remote_repo )
254+ ran_fetch_test = True
255+ # END fetch test
219256
220257 # PULL TESTING
221258 self ._test_push_and_pull (remote , rw_repo , remote_repo )
222259
223260 remote .update ()
224261 # END for each remote
225262
263+ assert ran_fetch_test
226264 assert num_remotes
227265 assert num_remotes == len (remote_set )
228266
0 commit comments