Commit 05c83591 authored by raphael.kubo.da.costa's avatar raphael.kubo.da.costa Committed by Commit bot

gclient_scm: Make calls to "git merge-base" non-fatal.

It might be the case for some repositories that there is no merge base
between the current git HEAD and origin/master, which causes git
merge-base to exit with a non-zero code and cause calls to gclient
status/diff/pack to fail, as well as gclient sync if the repository in
question has been removed from DEPS.

This is true for the external/webrtc/trunk/talk repository, for example.
Its recent release branches (branch-heads/45 all the way to /53 at
least) have no ancestry shared with its master branch, so gclient
sync'ing from a Chromium M51 checkout to an M52 one (where it's no
longer in DEPS) fails because of the failed git merge-base calls.

We now ignore failures and just don't specify a merge base when calling
"git diff".

BUG=633962
R=iannucci@chromium.org,agable@chromium.org,maruel@chromium.org

Review-Url: https://codereview.chromium.org/2215673002
parent eaca0336
...@@ -292,8 +292,11 @@ class GitWrapper(SCMWrapper): ...@@ -292,8 +292,11 @@ class GitWrapper(SCMWrapper):
""" """
def diff(self, options, _args, _file_list): def diff(self, options, _args, _file_list):
merge_base = self._Capture(['merge-base', 'HEAD', self.remote]) try:
self._Run(['diff', merge_base], options) merge_base = [self._Capture(['merge-base', 'HEAD', self.remote])]
except subprocess2.CalledProcessError:
merge_base = []
self._Run(['diff'] + merge_base, options)
def pack(self, _options, _args, _file_list): def pack(self, _options, _args, _file_list):
"""Generates a patch file which can be applied to the root of the """Generates a patch file which can be applied to the root of the
...@@ -302,9 +305,12 @@ class GitWrapper(SCMWrapper): ...@@ -302,9 +305,12 @@ class GitWrapper(SCMWrapper):
The patch file is generated from a diff of the merge base of HEAD and The patch file is generated from a diff of the merge base of HEAD and
its upstream branch. its upstream branch.
""" """
merge_base = self._Capture(['merge-base', 'HEAD', self.remote]) try:
merge_base = [self._Capture(['merge-base', 'HEAD', self.remote])]
except subprocess2.CalledProcessError:
merge_base = []
gclient_utils.CheckCallAndFilter( gclient_utils.CheckCallAndFilter(
['git', 'diff', merge_base], ['git', 'diff'] + merge_base,
cwd=self.checkout_path, cwd=self.checkout_path,
filter_fn=GitDiffFilterer(self.relpath, print_func=self.Print).Filter) filter_fn=GitDiffFilterer(self.relpath, print_func=self.Print).Filter)
...@@ -785,11 +791,14 @@ class GitWrapper(SCMWrapper): ...@@ -785,11 +791,14 @@ class GitWrapper(SCMWrapper):
self.Print('________ couldn\'t run status in %s:\n' self.Print('________ couldn\'t run status in %s:\n'
'The directory does not exist.' % self.checkout_path) 'The directory does not exist.' % self.checkout_path)
else: else:
merge_base = self._Capture(['merge-base', 'HEAD', self.remote]) try:
self._Run(['diff', '--name-status', merge_base], options, merge_base = [self._Capture(['merge-base', 'HEAD', self.remote])]
except subprocess2.CalledProcessError:
merge_base = []
self._Run(['diff', '--name-status'] + merge_base, options,
stdout=self.out_fh) stdout=self.out_fh)
if file_list is not None: if file_list is not None:
files = self._Capture(['diff', '--name-only', merge_base]).split() files = self._Capture(['diff', '--name-only'] + merge_base).split()
file_list.extend([os.path.join(self.checkout_path, f) for f in files]) file_list.extend([os.path.join(self.checkout_path, f) for f in files])
def GetUsableRev(self, rev, options): def GetUsableRev(self, rev, options):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment