@@ -41,7 +41,7 @@ def wrapper(self, *args, **kwargs):
41
41
wrapper .__name__ = func .__name__
42
42
return wrapper
43
43
44
- def find_remote_branch (remotes , branch ):
44
+ def find_first_remote_branch (remotes , branch ):
45
45
"""Find the remote branch matching the name of the given branch or raise InvalidGitRepositoryError"""
46
46
for remote in remotes :
47
47
try :
@@ -394,7 +394,7 @@ def update(self, recursive=False, init=True, to_latest_revision=False):
394
394
# see whether we have a valid branch to checkout
395
395
try :
396
396
# 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 )
398
398
local_branch = self .branch
399
399
if not local_branch .is_valid ():
400
400
# 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=
1078
1078
# new remote branch
1079
1079
smm = sm .module ()
1080
1080
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
1083
1091
1092
+ tbr .set_tracking_branch (find_first_remote_branch (smmr , sm .branch ))
1084
1093
# figure out whether the previous tracking branch contains
1085
1094
# new commits compared to the other one, if not we can
1086
1095
# delete it.
1087
1096
try :
1088
- tbr = find_remote_branch (smmr , psm .branch )
1097
+ tbr = find_first_remote_branch (smmr , psm .branch )
1089
1098
if len (smm .git .cherry (tbr , psm .branch )) == 0 :
1090
1099
psm .branch .delete (smm , psm .branch )
1091
1100
#END delete original tracking branch if there are no changes
0 commit comments