-
Notifications
You must be signed in to change notification settings - Fork 0
/
cherry_pick.py
60 lines (48 loc) · 2.15 KB
/
cherry_pick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import subprocess
def run_command(command, wait=True):
"""Executa um comando no shell e retorna a saída."""
if wait:
result = subprocess.run(command, shell=True, text=True, capture_output=True)
if result.returncode != 0:
print(f"Erro ao executar comando: {command}")
print(result.stderr)
return result
else:
subprocess.run(command, shell=True)
def get_commit_message(commit_hash):
"""Obtém a mensagem do commit com base no hash."""
command = f"git log -1 --pretty=%B {commit_hash}"
result = run_command(command)
if result.returncode == 0:
return result.stdout.strip()
else:
return ""
def cherry_pick_commits(start_commit, end_commit):
"""Realiza o cherry-pick dos commits entre start_commit e end_commit."""
# Obtém a lista de commits no intervalo especificado
command = f"git log --reverse --format=%H {start_commit}..{end_commit}"
result = run_command(command)
if result.returncode != 0:
print("Falha ao obter a lista de commits.")
return
commits = result.stdout.strip().split("\n")
for commit in commits:
# Verifica a mensagem do commit
commit_message = get_commit_message(commit)
# print(f"Processando commit {commit}: {commit_message}")
# Se a mensagem do commit contém "LTS: Update to", abra o Neovim
if "LTS: Update to" in commit_message:
print(f"Abrindo Neovim para o commit {commit}...")
run_command("nvim Makefile", wait=False)
input("Pressione Enter para continuar após fechar o Neovim...")
print(f"Aplicando cherry-pick no commit {commit}...")
result = run_command(f"git cherry-pick {commit}")
if result.returncode != 0:
print(f"Conflito no commit {commit}. Pulando...")
run_command("git cherry-pick --skip")
else:
print(f"Commit {commit} aplicado com sucesso.")
if __name__ == "__main__":
start_commit = input("Digite o hash do commit inicial: ")
end_commit = input("Digite o hash do commit final: ")
cherry_pick_commits(start_commit, end_commit)