Skip to content

Commit c44ad09

Browse files
Jeroen DhollanderLUCI
authored andcommitted
Add a --rebase option to sync command
Previously repo would abort a sync if there were published changes not merged upstream. The --rebase option allows the modification of published commits. This is a copy of http://go/grev/369694 with the merge conflicts resolved. Bug: 40014610 Change-Id: Idac8199400346327b530abea33f1ed794e5bb4c2 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/435838 Reviewed-by: Josip Sokcevic <[email protected]> Tested-by: Jeroen Dhollander <[email protected]> Commit-Queue: Jeroen Dhollander <[email protected]>
1 parent 4592a63 commit c44ad09

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

project.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,7 @@ def Sync_LocalHalf(
15351535
syncbuf,
15361536
force_sync=False,
15371537
force_checkout=False,
1538+
force_rebase=False,
15381539
submodules=False,
15391540
errors=None,
15401541
verbose=False,
@@ -1680,14 +1681,15 @@ def _dosubmodules():
16801681
if pub:
16811682
not_merged = self._revlist(not_rev(revid), pub)
16821683
if not_merged:
1683-
if upstream_gain:
1684+
if upstream_gain and not force_rebase:
16841685
# The user has published this branch and some of those
16851686
# commits are not yet merged upstream. We do not want
16861687
# to rewrite the published commits so we punt.
16871688
fail(
16881689
LocalSyncFail(
16891690
"branch %s is published (but not merged) and is "
1690-
"now %d commits behind"
1691+
"now %d commits behind. Fix this manually or rerun "
1692+
"with the --rebase option to force a rebase."
16911693
% (branch.name, len(upstream_gain)),
16921694
project=self.name,
16931695
)

subcmds/sync.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ def _Options(self, p, show_smart=True):
400400
"projects no longer exist in the manifest. "
401401
"WARNING: this may cause loss of data",
402402
)
403+
p.add_option(
404+
"--rebase",
405+
dest="rebase",
406+
action="store_true",
407+
help="rebase local commits regardless of whether they are "
408+
"published",
409+
)
403410
p.add_option(
404411
"-l",
405412
"--local-only",
@@ -1009,7 +1016,13 @@ def _FetchMain(
10091016
return _FetchMainResult(all_projects)
10101017

10111018
def _CheckoutOne(
1012-
self, detach_head, force_sync, force_checkout, verbose, project
1019+
self,
1020+
detach_head,
1021+
force_sync,
1022+
force_checkout,
1023+
force_rebase,
1024+
verbose,
1025+
project,
10131026
):
10141027
"""Checkout work tree for one project
10151028
@@ -1019,6 +1032,7 @@ def _CheckoutOne(
10191032
existing git directory that was previously linked to a different
10201033
object directory).
10211034
force_checkout: Force checking out of the repo content.
1035+
force_rebase: Force rebase.
10221036
verbose: Whether to show verbose messages.
10231037
project: Project object for the project to checkout.
10241038
@@ -1036,6 +1050,7 @@ def _CheckoutOne(
10361050
syncbuf,
10371051
force_sync=force_sync,
10381052
force_checkout=force_checkout,
1053+
force_rebase=force_rebase,
10391054
errors=errors,
10401055
verbose=verbose,
10411056
)
@@ -1109,6 +1124,7 @@ def _ProcessResults(pool, pm, results):
11091124
opt.detach_head,
11101125
opt.force_sync,
11111126
opt.force_checkout,
1127+
opt.rebase,
11121128
opt.verbose,
11131129
),
11141130
projects,

0 commit comments

Comments
 (0)