@@ -41,7 +41,7 @@ def wrapper(self, *args, **kwargs):
4141 wrapper .__name__ = func .__name__
4242 return wrapper
4343
44- def find_remote_branch (remotes , branch ):
44+ def find_first_remote_branch (remotes , branch ):
4545 """Find the remote branch matching the name of the given branch or raise InvalidGitRepositoryError"""
4646 for remote in remotes :
4747 try :
@@ -394,7 +394,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False):
394394 # see whether we have a valid branch to checkout
395395 try :
396396 # find a remote which has our branch - we try to be flexible
397- remote_branch = find_remote_branch (mrepo .remotes , self .branch )
397+ remote_branch = find_first_remote_branch (mrepo .remotes , self .branch )
398398 local_branch = self .branch
399399 if not local_branch .is_valid ():
400400 # Setup a tracking configuration - branch doesn't need to
@@ -1078,14 +1078,23 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
10781078 # new remote branch
10791079 smm = sm .module ()
10801080 smmr = smm .remotes
1081- tbr = git .Head .create (smm , sm .branch .name )
1082- tbr .set_tracking_branch (find_remote_branch (smmr , sm .branch ))
1081+ try :
1082+ tbr = git .Head .create (smm , sm .branch .name )
1083+ except git .GitCommandError , e :
1084+ if e .status != 128 :
1085+ raise
1086+ #END handle something unexpected
1087+
1088+ # ... or reuse the existing one
1089+ tbr = git .Head (smm , git .Head .to_full_path (sm .branch .name ))
1090+ #END assure tracking branch exists
10831091
1092+ tbr .set_tracking_branch (find_first_remote_branch (smmr , sm .branch ))
10841093 # figure out whether the previous tracking branch contains
10851094 # new commits compared to the other one, if not we can
10861095 # delete it.
10871096 try :
1088- tbr = find_remote_branch (smmr , psm .branch )
1097+ tbr = find_first_remote_branch (smmr , psm .branch )
10891098 if len (smm .git .cherry (tbr , psm .branch )) == 0 :
10901099 psm .branch .delete (smm , psm .branch )
10911100 #END delete original tracking branch if there are no changes
0 commit comments