Skip to content

Commit e4872ac

Browse files
Jeroen DhollanderLUCI
authored andcommitted
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 <[email protected]> Tested-by: Jeroen Dhollander <[email protected]> Commit-Queue: Jeroen Dhollander <[email protected]>
1 parent 4623264 commit e4872ac

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

project.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,9 @@ def _doff():
15891589
self._FastForward(revid)
15901590
self._CopyAndLinkFiles()
15911591

1592+
def _dorebase():
1593+
self._Rebase(upstream="@{upstream}")
1594+
15921595
def _dosubmodules():
15931596
self._SyncSubmodules(quiet=True)
15941597

@@ -1680,19 +1683,24 @@ def _dosubmodules():
16801683
if pub:
16811684
not_merged = self._revlist(not_rev(revid), pub)
16821685
if not_merged:
1683-
if upstream_gain and not force_rebase:
1684-
# The user has published this branch and some of those
1685-
# commits are not yet merged upstream. We do not want
1686-
# to rewrite the published commits so we punt.
1687-
fail(
1688-
LocalSyncFail(
1689-
"branch %s is published (but not merged) and is "
1690-
"now %d commits behind. Fix this manually or rerun "
1691-
"with the --rebase option to force a rebase."
1692-
% (branch.name, len(upstream_gain)),
1693-
project=self.name,
1686+
if upstream_gain:
1687+
if force_rebase:
1688+
# Try to rebase local published but not merged changes
1689+
# on top of the upstream changes.
1690+
syncbuf.later1(self, _dorebase, not verbose)
1691+
else:
1692+
# The user has published this branch and some of those
1693+
# commits are not yet merged upstream. We do not want
1694+
# to rewrite the published commits so we punt.
1695+
fail(
1696+
LocalSyncFail(
1697+
"branch %s is published (but not merged) and "
1698+
"is now %d commits behind. Fix this manually "
1699+
"or rerun with the --rebase option to force a "
1700+
"rebase." % (branch.name, len(upstream_gain)),
1701+
project=self.name,
1702+
)
16941703
)
1695-
)
16961704
return
16971705
syncbuf.later1(self, _doff, not verbose)
16981706
return

0 commit comments

Comments
 (0)