2
0

rename-branch.py 791 B

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