From e4872ac8baec782c86222ca93efb4a7c9b9e0c7b Mon Sep 17 00:00:00 2001 From: Jeroen Dhollander Date: Wed, 15 Oct 2025 17:27:09 +0200 Subject: sync: Use 'git rebase' during 'repo sync --rebase' 'repo sync --rebase' should do a rebase if it encounters local commits during a 'repo sync'. This was broken by https://gerrit-review.git.corp.google.com/c/git-repo/+/437421, which caused this to execute the '_doff' hook (which stands for 'do fast forward'), which is implemented using 'git merge --no-stat'. This caused *multiple* actual editor windows to pop up (*) during 'repo sync --rebase', asking the user to enter a commit message for the merge. In this CL I explicitly make that code path do a 'git rebase'. (*) and if you use a terminal editor like 'vim', this means you have 2+ concurrent vim windows rendered in the same terminal, while 'repo sync' keeps on printing other output lines, again in the same terminal. The result is .... not pretty to say the least :( Bug: b:434565811 Test: Used it myself for over a week. Change-Id: I0bf3ff181f15b9d5b2e3f85f7f84e302139fdab7 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/518602 Reviewed-by: Mike Frysinger Tested-by: Jeroen Dhollander Commit-Queue: Jeroen Dhollander --- project.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'project.py') diff --git a/project.py b/project.py index dfc20098..8e430175 100644 --- a/project.py +++ b/project.py @@ -1589,6 +1589,9 @@ class Project: self._FastForward(revid) self._CopyAndLinkFiles() + def _dorebase(): + self._Rebase(upstream="@{upstream}") + def _dosubmodules(): self._SyncSubmodules(quiet=True) @@ -1680,19 +1683,24 @@ class Project: if pub: not_merged = self._revlist(not_rev(revid), pub) if not_merged: - if upstream_gain and not force_rebase: - # The user has published this branch and some of those - # commits are not yet merged upstream. We do not want - # to rewrite the published commits so we punt. - fail( - LocalSyncFail( - "branch %s is published (but not merged) and is " - "now %d commits behind. Fix this manually or rerun " - "with the --rebase option to force a rebase." - % (branch.name, len(upstream_gain)), - project=self.name, + if upstream_gain: + if force_rebase: + # Try to rebase local published but not merged changes + # on top of the upstream changes. + syncbuf.later1(self, _dorebase, not verbose) + else: + # The user has published this branch and some of those + # commits are not yet merged upstream. We do not want + # to rewrite the published commits so we punt. + fail( + LocalSyncFail( + "branch %s is published (but not merged) and " + "is now %d commits behind. Fix this manually " + "or rerun with the --rebase option to force a " + "rebase." % (branch.name, len(upstream_gain)), + project=self.name, + ) ) - ) return syncbuf.later1(self, _doff, not verbose) return -- cgit v1.2.3-54-g00ecf