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.
pull/12364/head
Nirbheek Chauhan 1 year ago committed by Nirbheek Chauhan
parent b78aa8f9e9
commit 3c6f04b294
  1. 21
      mesonbuild/msubprojects.py

@ -287,6 +287,19 @@ class Runner:
success = self.git_rebase(revision)
return success
def git_branch_has_upstream(self, urls: set) -> bool:
cmd = ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}']
ret, upstream = quiet_git(cmd, self.repo_dir)
if not ret:
return False
try:
remote = upstream.split('/', maxsplit=1)[0]
except IndexError:
return False
cmd = ['remote', 'get-url', remote]
ret, remote_url = quiet_git(cmd, self.repo_dir)
return remote_url.strip() in urls
def update_git(self) -> bool:
options = T.cast('UpdateArguments', self.options)
if not os.path.exists(os.path.join(self.repo_dir, '.git')):
@ -378,10 +391,14 @@ class Runner:
success = self.git_rebase(revision)
else:
# We are in another branch, either the user created their own branch and
# we should rebase it, or revision changed in the wrap file and we need
# to checkout the new branch.
# we should rebase it, or revision changed in the wrap file (we
# know this when the current branch has an upstream) and we need to
# checkout the new branch.
if options.reset:
success = self.git_checkout_and_reset(revision)
else:
if self.git_branch_has_upstream({url, push_url}):
success = self.git_checkout_and_rebase(revision)
else:
success = self.git_rebase(revision)
if success:

Loading…
Cancel
Save