Skip to content
Browse files
Utility script to help with Weblate commit import
  • Loading branch information
sfan5 committed Apr 3, 2020
1 parent b6d2c34 commit fe21aa1f4a92f54df2ed0f240472ce9a42fe473c
Showing 1 changed file with 33 additions and 0 deletions.
@@ -0,0 +1,33 @@
#!/usr/bin/env python3
import sys
import subprocess

ret =["git", "config", "rebase.instructionFormat"], capture_output=True)
if ret.returncode != 0 or ret.stdout.decode('ascii').strip() != "(%an <%ae>) %s":
print("Git is using the wrong rebase instruction format, reconfigure it.")

f = open(".git/rebase-merge/git-rebase-todo", "r")
print("Initiate the rebase first!")
lines = list(s.strip("\r\n") for s in f.readlines())

for i in range(len(lines)):
line = lines[i]
if line.startswith("#") or " Translated using Weblate " not in line: continue
pos = line.rfind("(")
lang = line[pos:]
author = line[line.find("("):line.rfind(")", 0, pos)+1]
# try to grab the next commit by the same author for the same language
for j in range(i+1, len(lines)):
if lines[j].startswith("#") or not lines[j].endswith(lang): continue
if author in lines[j]:
lines.insert(i+1, "f " + lines.pop(j)[5:])

with open(".git/rebase-merge/git-rebase-todo", "w") as f:
f.write("\n".join(lines) + "\n")
print("You can now continue with the rebase.")

0 comments on commit fe21aa1

Please sign in to comment.