@@ -38,11 +38,19 @@ def _test_fetch(self,remote, rw_repo, remote_repo):
3838 # specialized fetch testing to de-clutter the main test
3939 self ._test_fetch_info (rw_repo )
4040
41+ def fetch_and_test (remote ):
42+ res = remote .fetch ()
43+ self ._test_fetch_result (res , remote )
44+ return res
45+ # END fetch and check
46+
47+ def get_info (res , remote , name ):
48+ return res ["%s/%s" % (remote ,name )]
49+
4150 # put remote head to master as it is garantueed to exist
4251 remote_repo .head .reference = remote_repo .heads .master
4352
44- res = remote .fetch ()
45- self ._test_fetch_result (res , remote )
53+ res = fetch_and_test (remote )
4654 # all uptodate
4755 for info in res :
4856 assert info .flags & info .BRANCH_UPTODATE
@@ -52,18 +60,40 @@ def _test_fetch(self,remote, rw_repo, remote_repo):
5260 rhead = remote_repo .head
5361 remote_commit = rhead .commit
5462 rhead .reset ("HEAD~2" , index = False )
55- res = remote .fetch ()
56- self ._test_fetch_result (res , remote )
57- mkey = "%s/master" % remote
63+ res = fetch_and_test (remote )
64+ mkey = "%s/%s" % (remote ,'master' )
5865 master_info = res [mkey ]
5966 assert master_info .flags & Remote .FetchInfo .FORCED_UPDATE and master_info .note is not None
6067
6168 # normal fast forward - set head back to previous one
6269 rhead .commit = remote_commit
63- res = remote .fetch ()
64- self ._test_fetch_result (res , remote )
70+ res = fetch_and_test (remote )
6571 assert res [mkey ].flags & Remote .FetchInfo .FAST_FORWARD
6672
73+ # new remote branch
74+ new_remote_branch = Head .create (remote_repo , "new_branch" )
75+ res = fetch_and_test (remote )
76+ new_branch_info = get_info (res , remote , new_remote_branch )
77+ assert new_branch_info .flags & Remote .FetchInfo .NEW_BRANCH
78+
79+ # remote branch rename ( causes creation of a new one locally )
80+ new_remote_branch .rename ("other_branch_name" )
81+ res = fetch_and_test (remote )
82+ other_branch_info = get_info (res , remote , new_remote_branch )
83+ assert other_branch_info .remote_ref .commit == new_branch_info .remote_ref .commit
84+
85+ # remove new branch
86+ Head .delete (new_remote_branch .repo , new_remote_branch )
87+ res = fetch_and_test (remote )
88+ # deleted remote will not be fetched
89+ self .failUnlessRaises (IndexError , get_info , res , remote , new_remote_branch )
90+
91+ # prune stale tracking branches
92+ stale_refs = remote .stale_refs
93+ assert len (stale_refs ) == 2 and isinstance (stale_refs [0 ], RemoteReference )
94+ RemoteReference .delete (rw_repo , * stale_refs )
95+
96+
6797 self .fail ("tag handling, tag uptodate, new tag, new branch" )
6898
6999 def _test_pull (self ,remote , rw_repo , remote_repo ):
@@ -89,7 +119,7 @@ def test_base(self, rw_repo, remote_repo):
89119 assert refs
90120 for ref in refs :
91121 assert ref .remote_name == remote .name
92- assert ref .remote_branch
122+ assert ref .remote_head
93123 # END for each ref
94124
95125 # OPTIONS
0 commit comments