Don't have checkout.py's git apply_patch fail when files don't match
The contract for apply_patch is that it applies a patch on top of something, and
it either all applies cleanly or it fails. The something that is applied on can
be as clean or dirty without having apply_patch judge. The particular failure
condition was that we want to patch DEPS first (into the index), do some stuff,
then apply another patch on top of that. Apply_patch was failing because it
saw that there was a DEPS in the index already when it wasn't expecting one.
A fix that could've also worked is to run git diff --staged before applying the
patch, then subtract that list from found_files, but it still gets tricky then
because what if you want to apply an independent patch on top of
an already patched index?
Because apply_patch shouldn't need to be in the business of
keeping track of what the state of everything is like before and
after a patch (That's up to the patch application), the better thing would be to remove the assert
alltogether, and rely on "git apply" to complain if something doesn't apply.
BUG=370503
TBR=iannucci
Review URL: https://codereview.chromium.org/280023004
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@269526 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/checkout.py b/checkout.py
index 68781cb..15d548c 100644
--- a/checkout.py
+++ b/checkout.py
@@ -707,10 +707,14 @@
found_files = self._check_output_git(
['diff', '--ignore-submodules',
'--name-only', '--staged']).splitlines(False)
- assert sorted(patches.filenames) == sorted(found_files), (
- 'Found extra %s locally, %s not patched' % (
- sorted(set(found_files) - set(patches.filenames)),
- sorted(set(patches.filenames) - set(found_files))))
+ if sorted(patches.filenames) != sorted(found_files):
+ extra_files = sorted(set(found_files) - set(patches.filenames))
+ unpatched_files = sorted(set(patches.filenames) - set(found_files))
+ if extra_files:
+ print 'Found extra files: %r' % (extra_files,)
+ if unpatched_files:
+ print 'Found unpatched files: %r' % (unpatched_files,)
+
def commit(self, commit_message, user):
"""Commits, updates the commit message and pushes."""