Created
March 26, 2022 09:52
-
-
Save jarkkojs/d9246534486fb2d883fe1f040e01144c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (C) Jarkko Sakkinen 2022 | |
#!/usr/bin/env python3 | |
import re | |
import sys | |
from git.repo import Repo | |
if __name__ == "__main__": | |
repo = Repo(sys.argv[1]) | |
# Fetch origin. | |
remote = repo.remote() | |
remote.fetch() | |
heads = list( | |
filter(lambda h: re.search("^(build|feat|fix|refactor)/", h.name), | |
repo.heads)) | |
references = list( | |
filter( | |
lambda r: re.search("^origin/(build|feat|fix|refactor)/", r.name), | |
repo.remote().refs)) | |
repo.git.checkout('main') | |
for head in heads: | |
print("Deleting " + head.name) | |
repo.delete_head(head) | |
for reference in references: | |
topic = reference.name.split('/', 1)[1] | |
print("Recreating " + topic) | |
repo.git.checkout(topic) | |
repo.git.checkout('main') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment