From 8ea2a3b846b7236dcc02ba9054ddb96b4635e2ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=BChnel?= Date: Fri, 8 May 2020 15:33:45 +0200 Subject: [PATCH] using different way for deleting remote branches --- scripts/cleanup_branches.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/cleanup_branches.py b/scripts/cleanup_branches.py index f51d49f..11dc139 100644 --- a/scripts/cleanup_branches.py +++ b/scripts/cleanup_branches.py @@ -32,7 +32,8 @@ def delete_old_branches(repo_path: str, max_age: datetime.datetime, branch_patte This script assumes that $repo_path contains a current checkout of the repository ot be cleaned up. """ repo = git.Repo(repo_path) - refs = repo.remotes[remote_name].refs + remote = repo.remote(name=remote_name) + refs = remote.refs print('Found {} references at {} in total.'.format(len(refs), remote_name)) del_count = 0 for reference in refs: @@ -42,14 +43,10 @@ def delete_old_branches(repo_path: str, max_age: datetime.datetime, branch_patte print('dryrun: would have deleted {}'.format(reference.name)) else: print('Deleting {}'.format(reference.name)) - git.RemoteReference.delete(repo.remotes[remote_name].repo, reference) + remote.push(refspec=':{}'.format(reference.remote_head)) del_count += 1 print('Deleted {} references.'.format(del_count)) - if not dry_run and del_count > 0: - print('Pushing deleted branches to remote...') - repo.remotes[remote_name].push() - print('Done.') def _has_pattern_match(name: str, patterns) -> bool: