Skip to content

Commit 428c89a

Browse files
committed
msubprojects: Checkout if the branch is tracking upstream
A rebase of the current branch is the wrong thing to do if the revision (branch) specified in the wrap changed, which is the case in the majority of cases, such as when switching from one release branch to another.
1 parent 11e5cac commit 428c89a

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

mesonbuild/msubprojects.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,19 @@ def git_checkout_and_rebase(self, revision: str) -> bool:
285285
success = self.git_rebase(revision)
286286
return success
287287

288+
def git_branch_has_upstream(self, urls: set) -> bool:
289+
cmd = ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}']
290+
ret, upstream = quiet_git(cmd, self.repo_dir)
291+
if not ret:
292+
return False
293+
try:
294+
remote = upstream.split('/', maxsplit=1)[0]
295+
except IndexError:
296+
return False
297+
cmd = ['remote', 'get-url', remote]
298+
ret, remote_url = quiet_git(cmd, self.repo_dir)
299+
return remote_url.strip() in urls
300+
288301
def update_git(self) -> bool:
289302
options = T.cast('UpdateArguments', self.options)
290303
if not os.path.exists(os.path.join(self.repo_dir, '.git')):
@@ -376,12 +389,16 @@ def update_git(self) -> bool:
376389
success = self.git_rebase(revision)
377390
else:
378391
# We are in another branch, either the user created their own branch and
379-
# we should rebase it, or revision changed in the wrap file and we need
380-
# to checkout the new branch.
392+
# we should rebase it, or revision changed in the wrap file (we
393+
# know this when the current branch has an upstream) and we need to
394+
# checkout the new branch.
381395
if options.reset:
382396
success = self.git_checkout_and_reset(revision)
383397
else:
384-
success = self.git_rebase(revision)
398+
if self.git_branch_has_upstream({url, push_url}):
399+
success = self.git_checkout_and_rebase(revision)
400+
else:
401+
success = self.git_rebase(revision)
385402
if success:
386403
self.update_git_done()
387404
return success

0 commit comments

Comments
 (0)