summaryrefslogtreecommitdiff
path: root/mesonbuild/msubprojects.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2023-10-07 03:10:41 +0530
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2023-10-11 23:48:13 +0530
commit3c6f04b29442ba1a06c572bf533b34fb91ef27ed (patch)
tree8c868e22eb10f9bb895f5c9c7cd0001630e3e4f5 /mesonbuild/msubprojects.py
parentb78aa8f9e98c01d7be87fcb1cbcbea2ba33fb84a (diff)
downloadmeson-3c6f04b29442ba1a06c572bf533b34fb91ef27ed.tar.gz
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.
Diffstat (limited to 'mesonbuild/msubprojects.py')
-rwxr-xr-xmesonbuild/msubprojects.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py
index 87905deb4..874364e18 100755
--- a/mesonbuild/msubprojects.py
+++ b/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,12 +391,16 @@ 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:
- success = self.git_rebase(revision)
+ if self.git_branch_has_upstream({url, push_url}):
+ success = self.git_checkout_and_rebase(revision)
+ else:
+ success = self.git_rebase(revision)
if success:
self.update_git_done()
return success