Skip to content

Commit

Permalink
msubprojects: Don't rebase if the branch is tracking upstream
Browse files Browse the repository at this point in the history
A rebase is the wrong thing to do if the subproject's branch is simply
tracking upstream with no local changes, which is the case in the
majority of cases. A rebase will actually fail in the majority of
cases, such as when switching from one release branch to another.
  • Loading branch information
nirbheek committed Oct 6, 2023
1 parent b452cc9 commit 27688ce
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion mesonbuild/msubprojects.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ def git_checkout_and_rebase(self, revision: str) -> bool:
success = self.git_rebase(revision)
return success

def git_local_branch_is_untouched(self, revision: str, branch: str) -> bool:
'''Check whether the local branch is still tracking upstream as-is without local changes'''
cmd = ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}']
(ret, o) = quiet_git(cmd, self.repo_dir)
if not ret:
# No upstream branch?
return False
upstream = o[:-1]
return quiet_git(['diff', '--quiet', f'{upstream}..{branch}'], self.repo_dir)[0]

def update_git(self) -> bool:
options = T.cast('UpdateArguments', self.options)
if not os.path.exists(os.path.join(self.repo_dir, '.git')):
Expand Down Expand Up @@ -383,7 +393,10 @@ def update_git(self) -> bool:
if options.reset:
success = self.git_checkout_and_reset(revision)
else:
success = self.git_rebase(revision)
if self.git_local_branch_is_untouched(revision, branch):
success = self.git_checkout_and_rebase(revision)
else:
success = self.git_rebase(revision)
if success:
self.update_git_done()
return success
Expand Down

0 comments on commit 27688ce

Please sign in to comment.