Skip to content

Commit 8396010

Browse files
committed
🔧 chore(core): test icons
1 parent 3c6373a commit 8396010

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

control_commit/main.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import argparse
1111
import logging
1212
import re
13+
import subprocess
1314
import sys
1415
from logging.handlers import RotatingFileHandler
1516

@@ -170,20 +171,25 @@ def add_icon_to_commit_message(commit_type: str, existing_commit_msg: str) -> st
170171
return existing_commit_msg
171172

172173

173-
def write_commit_message(file_path: str, commit_msg: str) -> None:
174+
def amend_commit(new_commit_msg: str) -> None:
174175
"""
175-
Writes the updated commit message back to the commit message file.
176+
Amends the current commit with the new commit message.
176177
177178
Args:
178-
file_path (str): Path to the commit message file.
179-
commit_msg (str): The updated commit message.
179+
new_commit_msg (str): The new commit message.
180+
181+
Raises:
182+
subprocess.CalledProcessError: If git amend fails.
180183
"""
181184
try:
182-
with open(file_path, "w", encoding="utf-8") as file:
183-
file.write(commit_msg + "\n")
184-
logger.debug(f"Commit message written to file: {file_path}")
185-
except Exception as e:
186-
logger.error(f"Error writing to commit message file: {e}")
185+
# Amend the commit with the new commit message
186+
subprocess.run(["git", "commit", "--amend", "-m", new_commit_msg], check=True)
187+
logger.info("Successfully amended the commit with the new commit message.")
188+
logger.info(
189+
"Please perform a push using 'git push' to update the remote repository. Avoid use --force"
190+
)
191+
except subprocess.CalledProcessError as e:
192+
logger.error(f"Failed to amend the commit: {e}")
187193
sys.exit(1)
188194

189195

@@ -253,7 +259,7 @@ def main() -> None:
253259
updated_commit_msg = add_icon_to_commit_message(commit_type, commit_msg)
254260

255261
# Write the updated commit message back to the file
256-
write_commit_message(commit_msg_file, updated_commit_msg)
262+
amend_commit(updated_commit_msg)
257263

258264
# Inform the user and abort the commit to allow them to review the amended message
259265
logger.info(

0 commit comments

Comments
 (0)