From bdf3ab4d8e2298d4dc8f6f200bdccdd32ad3ac50 Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Mon, 30 Aug 2021 08:57:18 -0700 Subject: [PATCH] Let the test mapping updater handle newly-added files. The previous commit to this file allowed it to create and upload a commit when a TEST_MAPPING file changed. But it did not handle the case where the TEST_MAPPING file did not previously exist. This fixes that. Test: Run script. Change-Id: Id7b9e778c2b084f7ea2e4005a173c1fedeccd6c7 --- scripts/update_crate_tests.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/update_crate_tests.py b/scripts/update_crate_tests.py index 1f04c1399..3b654fc55 100755 --- a/scripts/update_crate_tests.py +++ b/scripts/update_crate_tests.py @@ -278,13 +278,17 @@ def main(): test_mapping = TestMapping(env, bazel, path) test_mapping.create() changed = (subprocess.call(['git', 'diff', '--quiet']) == 1) - if changed and args.branch_and_commit: + untracked = (os.path.isfile('TEST_MAPPING') and + (subprocess.run(['git', 'ls-files', '--error-unmatch', 'TEST_MAPPING'], + stderr=subprocess.DEVNULL, + stdout=subprocess.DEVNULL).returncode == 1)) + if args.branch_and_commit and (changed or untracked): subprocess.check_output(['repo', 'start', 'tmp_auto_test_mapping', '.']) subprocess.check_output(['git', 'add', 'TEST_MAPPING']) subprocess.check_output(['git', 'commit', '-m', 'Update TEST_MAPPING\n\nTest: None']) - if changed and args.push_change: + if args.push_change and (changed or untracked): date = datetime.today().strftime('%m-%d') subprocess.check_output(['git', 'push', 'aosp', 'HEAD:refs/for/master', '-o', 'topic=test-mapping-%s' % date])