Merge "Support recent git changes to merge options"

This commit is contained in:
Zuul 2018-04-27 17:59:00 +00:00 committed by Gerrit Code Review
commit 954604e8fe
2 changed files with 33 additions and 4 deletions

View File

@ -219,7 +219,15 @@ class ImportUpstream(LogDedentMixin, GitMixin):
# as normal merge (with octopus strategy) will refuse if you
# are merging in more than one branch without a common
# ancestor to the current tree.
self.git.merge(*self.extra_branches, s="ours", no_commit=True)
try:
self.git.merge(*self.extra_branches, s="ours", no_commit=True)
except GitCommandError as exc:
if 'refusing to merge unrelated histories' in exc.stderr:
self.git.merge(*self.extra_branches, s="ours",
no_commit=True,
allow_unrelated_histories=True)
else:
raise
self.git.read_tree(empty=True)
self.git.read_tree("HEAD", *self.extra_branches)
self.git.checkout("--", ".")

View File

@ -224,16 +224,37 @@ class BuildTree(object):
# trees of the nodes prefixed with '='
use = [str(self.graph[p.lstrip("=")])
for p in parents if p.startswith("=")]
self.git.merge(*commits, s="ours", no_commit=True)
try:
self.git.merge(*commits, s="ours", no_commit=True)
except git.exc.GitCommandError as exc:
if 'refusing to merge unrelated histories' in exc.stderr:
self.git.merge(*commits, s="ours", no_commit=True,
allow_unrelated_histories=True)
else:
raise
self.git.read_tree(empty=True)
self.git.read_tree(*use, u=True, reset=True)
elif len(commits) < 2:
# standard merge
self.git.merge(*commits, no_commit=True)
try:
self.git.merge(*commits, no_commit=True)
except git.exc.GitCommandError as exc:
if 'refusing to merge unrelated histories' in exc.stderr:
self.git.merge(*commits, no_commit=True,
allow_unrelated_histories=True)
else:
raise
else:
# multi-branch merge, git is not great at handling
# merging multiple orphaned branches
self.git.merge(*commits, s="ours", no_commit=True)
try:
self.git.merge(*commits, s="ours", no_commit=True)
except git.exc.GitCommandError as exc:
if 'refusing to merge unrelated histories' in exc.stderr:
self.git.merge(*commits, s="ours", no_commit=True,
allow_unrelated_histories=True)
else:
raise
self.git.read_tree(empty=True)
self.git.read_tree("HEAD", *commits)
self.git.checkout("--", ".")