Commit 8f0d06ed authored by Valentin Benozillo's avatar Valentin Benozillo

Add new file

parents
file_path = '.git/rebase-merge/git-rebase-todo'
original_commit_list = []
fixup_commit_list = []
verification_list = []
original_to_fixup_list_dict = {}
# Open the file in read mode
with open(file_path, 'r') as file:
# Read all lines from the file and store them in a list
lines = file.readlines()
for line in lines:
if line.strip() == '':
break
verification_list.append(line.split(' ')[1])
if 'fixup!' in line:
fixup_commit = line.strip()
fixup_original_message = fixup_commit.split('fixup! ')[-1]
already_found = False
for original_commit in original_commit_list:
if fixup_original_message in original_commit:
assert not already_found
original_to_fixup_list_dict[original_commit] = original_to_fixup_list_dict.get(original_commit, []) + [fixup_commit.replace('pick', 'f', 1)]
already_found = True
if already_found:
fixup_commit_list.append(fixup_commit)
else:
original_commit_list.append(line.strip())
else:
original_commit_list.append(line.strip())
result_list = []
for original_commit in original_commit_list :
result_list.append(original_commit)
fixup_commit_sub_list = original_to_fixup_list_dict.get(original_commit, False)
if fixup_commit_sub_list:
for fixup_commit in fixup_commit_sub_list:
result_list.append(fixup_commit)
assert len(original_commit_list) + len(fixup_commit_list) == len(result_list), '%d %d' % (len(lines), len(result_list))
result_string = '\n'.join(result_list)
for hash in verification_list:
assert hash in result_string
#print('\n'.join(result_list))
with open(file_path, 'w') as file:
file.write(result_string)
"""
# Print the list of lines
print(fixup_commit_list)
print(original_commit_list)
pick 0187235284 fixup! sanef_fr_base: Add Process Suspended Subscription Request alarm
"""
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment