reorder_translation_commits.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python3
  2. import sys
  3. import subprocess
  4. ret = subprocess.run(["git", "config", "rebase.instructionFormat"], capture_output=True)
  5. if ret.returncode != 0 or ret.stdout.decode('ascii').strip() != "(%an <%ae>) %s":
  6. print("Git is using the wrong rebase instruction format, reconfigure it.")
  7. exit(1)
  8. try:
  9. f = open(".git/rebase-merge/git-rebase-todo", "r")
  10. except:
  11. print("Initiate the rebase first!")
  12. exit(1)
  13. lines = list(s.strip("\r\n") for s in f.readlines())
  14. f.close()
  15. for i in range(len(lines)):
  16. line = lines[i]
  17. if line.startswith("#") or " Translated using Weblate " not in line: continue
  18. pos = line.rfind("(")
  19. lang = line[pos:]
  20. author = line[line.find("("):line.rfind(")", 0, pos)+1]
  21. # try to grab the next commit by the same author for the same language
  22. for j in range(i+1, len(lines)):
  23. if lines[j].startswith("#") or not lines[j].endswith(lang): continue
  24. if author in lines[j]:
  25. lines.insert(i+1, "f " + lines.pop(j)[5:])
  26. break
  27. with open(".git/rebase-merge/git-rebase-todo", "w") as f:
  28. f.write("\n".join(lines) + "\n")
  29. print("You can now continue with the rebase.")