From 6fb2c53be82a384b1ec21af28787d5fef1295978 Mon Sep 17 00:00:00 2001 From: Mikhail Goncharov Date: Mon, 29 Jun 2020 11:07:05 +0200 Subject: [PATCH] cleanup script logging and failure count fix --- scripts/cleanup_branches.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/scripts/cleanup_branches.py b/scripts/cleanup_branches.py index ce7eaab..b336982 100755 --- a/scripts/cleanup_branches.py +++ b/scripts/cleanup_branches.py @@ -40,22 +40,19 @@ def delete_old_branches(repo_path: str, max_age: datetime.datetime, branch_patte print('Found {} branches at {} in total.'.format(len(refs), remote_name)) del_count = 0 fail_count = 0 + if dry_run: + print('DRY RUN NO BRANCHES WILL BE DELETED', flush=True) for reference in refs: committed_date = datetime.datetime.fromtimestamp(reference.commit.committed_date) if committed_date < max_age and _has_pattern_match(reference.name, branch_patterns): - if dry_run: - print('dryrun: would have been deleted {}'.format(reference.name)) - sys.stdout.flush() - else: - print('Deleting {}'.format(reference.name)) - sys.stdout.flush() + print('Deleting {}'.format(reference.name), flush=True) + del_count += 1 + if not dry_run: try: remote.push(refspec=':{}'.format(reference.remote_head)) - del_count += 1 except git.GitCommandError: - print('ERROR: Failed to delete {}.'.format(reference.name)) - fail_count = 0 - + print('ERROR: Failed to delete {}.'.format(reference.name), flush=True) + fail_count += 1 print('Deleted {} branches.'.format(del_count)) if fail_count > 0: print('Failed to delete {} branches.'.format(fail_count))