From 2ba5a1e96347e735b12998c057a6c1eed79712e9 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 23 Sep 2019 17:42:23 -0400 Subject: sync: try to fast forward merge branches before checking published state If the local branch changed state since its last upload, the data cached in .git/config related to the last uploaded CL might not be that relevant. If we're able to fast forward merge to the latest tree state, then let's do that. This would be akin to checking out a detached head before syncing where we already switch state. If we aren't able to fast forward merge, then it's not a big deal as we'll continue on to the existing branch checking logic. This would be easy to reproduce by doing something like: $ repo start foo . $ git revert HEAD $ repo upload --cbr . $ git reset --hard HEAD^ $ repo sync . Change-Id: I7d62f3d1ba5314a349d85b4dbb0ec8352eca18bb Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/238552 Tested-by: Mike Frysinger Reviewed-by: Michael Mortensen Reviewed-by: Mike Frysinger --- project.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'project.py') diff --git a/project.py b/project.py index 3d22998e..5ffa5424 100755 --- a/project.py +++ b/project.py @@ -1586,7 +1586,16 @@ class Project(object): return upstream_gain = self._revlist(not_rev(HEAD), revid) - pub = self.WasPublished(branch.name, all_refs) + + # See if we can perform a fast forward merge. This can happen if our + # branch isn't in the exact same state as we last published. + try: + self.work_git.merge_base('--is-ancestor', HEAD, revid) + # Skip the published logic. + pub = False + except GitError: + pub = self.WasPublished(branch.name, all_refs) + if pub: not_merged = self._revlist(not_rev(revid), pub) if not_merged: -- cgit v1.2.3-54-g00ecf