2
0

rename-branch.py 786 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/python3
  2. from dulwich.client import get_transport_and_path_from_url
  3. from dulwich.objects import ZERO_SHA
  4. from dulwich.pack import pack_objects_to_data
  5. import argparse
  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 %s to %s" % (args.old_ref, args.new_ref))