rename-branch.py 822 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/python3
  2. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  3. import argparse
  4. from dulwich.client import get_transport_and_path_from_url
  5. from dulwich.objects import ZERO_SHA
  6. from dulwich.pack import pack_objects_to_data
  7. parser = argparse.ArgumentParser()
  8. parser.add_argument("url", type=str)
  9. parser.add_argument("old_ref", type=str)
  10. parser.add_argument("new_ref", type=str)
  11. args = parser.parse_args()
  12. client, path = get_transport_and_path_from_url(args.url)
  13. def generate_pack_data(*args, **kwargs):
  14. return pack_objects_to_data([])
  15. def update_refs(refs):
  16. sha = refs[args.old_ref.encode("utf-8")]
  17. return {args.old_ref.encode("utf-8"): ZERO_SHA, args.new_ref.encode("utf-8"): sha}
  18. client.send_pack(path, update_refs, generate_pack_data)
  19. print(f"Renamed {args.old_ref} to {args.new_ref}")