Support recent git changes to merge options

Git 2.9+ requires an explicit option to merge unrelated
histories together. Switch all the merge commands to try
to merge without this option and call it if the stderr
indicates that it is explicitly needed.

Change-Id: I929b310126ed0ae4d6c9726e81d86c0609c3b6e2
This commit is contained in:
Darragh Bailey 2018-03-10 10:17:04 +00:00
parent 3e1718f87c
commit f54e0d120d
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("--", ".")