From 96e179bba0f81a12ed57c9840f1ad4b060bc20cd Mon Sep 17 00:00:00 2001 From: agable Date: Fri, 24 Jun 2016 10:32:51 -0700 Subject: [PATCH] Better error checking in git freeze R=iannucci@chromium.org BUG=567157 Review-Url: https://codereview.chromium.org/1527403002 --- git_common.py | 13 +++++++++++-- tests/git_common_test.py | 11 +++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/git_common.py b/git_common.py index 03d99ee3f..9ccbbc35a 100644 --- a/git_common.py +++ b/git_common.py @@ -431,15 +431,24 @@ def freeze(): except subprocess2.CalledProcessError: pass + add_errors = False + try: + run('add', '-A', '--ignore-errors') + except subprocess2.CalledProcessError: + add_errors = True + try: - run('add', '-A') run('commit', '--no-verify', '-m', FREEZE + '.unindexed') took_action = True except subprocess2.CalledProcessError: pass + ret = [] + if add_errors: + ret.append('Failed to index some unindexed files.') if not took_action: - return 'Nothing to freeze.' + ret.append('Nothing to freeze.') + return ' '.join(ret) or None def get_branch_tree(): diff --git a/tests/git_common_test.py b/tests/git_common_test.py index c44524dd7..4b6a1d269 100755 --- a/tests/git_common_test.py +++ b/tests/git_common_test.py @@ -872,6 +872,17 @@ class GitFreezeThaw(git_test_utils.GitRepoReadWriteTestBase): self.repo.run(inner) + def testAddError(self): + def inner(): + self.repo.git('checkout', '-b', 'unreadable_file_branch') + with open('bad_file', 'w') as f: + f.write('some text') + os.chmod('bad_file', 0111) + ret = self.repo.run(self.gc.freeze) + self.assertIn('Failed to index some unindexed files.', ret) + + self.repo.run(inner) + class GitMakeWorkdir(git_test_utils.GitRepoReadOnlyTestBase, GitCommonTestBase): def setUp(self):