From 3223de0f5cd9b4073258e515af0e398fb2d40cff Mon Sep 17 00:00:00 2001 From: Kenneth Karlsson <24266371+karlssonkennneth@users.noreply.github.com> Date: Thu, 31 Jul 2025 14:27:40 +0200 Subject: [PATCH] refactor: Remove automatic push after commit Commit and push serve two different purposes. Commit creates a local history while push shares your changes. Users might want to amend the commit, or review it before pushing. There are also different tools used for pushing the code. At companies using Gerrit, the git-review tool is commonly used for pushing the code. https://docs.opendev.org/opendev/git-review/latest/index.html --- .../cli/conventional_commit_handler.py | 3 -- .../cli/gen_ai_commit_message_handler.py | 3 -- ai_commit_msg/utils/git_utils.py | 30 ------------------- 3 files changed, 36 deletions(-) delete mode 100644 ai_commit_msg/utils/git_utils.py diff --git a/ai_commit_msg/cli/conventional_commit_handler.py b/ai_commit_msg/cli/conventional_commit_handler.py index 3f5d094..ed1f566 100644 --- a/ai_commit_msg/cli/conventional_commit_handler.py +++ b/ai_commit_msg/cli/conventional_commit_handler.py @@ -3,7 +3,6 @@ from ai_commit_msg.utils.logger import Logger from ai_commit_msg.utils.utils import execute_cli_command from ai_commit_msg.utils.error import AIModelHandlerError -from ai_commit_msg.utils.git_utils import handle_git_push COMMIT_TYPES = { @@ -163,5 +162,3 @@ def conventional_commit_handler(args): return execute_cli_command(["git", "commit", "-m", f'"{formatted_commit}"'], output=True) - - handle_git_push() \ No newline at end of file diff --git a/ai_commit_msg/cli/gen_ai_commit_message_handler.py b/ai_commit_msg/cli/gen_ai_commit_message_handler.py index ba03e17..6f6e303 100644 --- a/ai_commit_msg/cli/gen_ai_commit_message_handler.py +++ b/ai_commit_msg/cli/gen_ai_commit_message_handler.py @@ -32,7 +32,6 @@ def gen_ai_commit_message_handler(): command_string = f""" git commit -m "{ai_gen_commit_msg}" -git push Would you like to commit your changes? (y/n): """ @@ -47,6 +46,4 @@ def gen_ai_commit_message_handler(): execute_cli_command(["git", "commit", "-m", ai_gen_commit_msg], output=True) - handle_git_push() - return 0 diff --git a/ai_commit_msg/utils/git_utils.py b/ai_commit_msg/utils/git_utils.py deleted file mode 100644 index 10e3bfd..0000000 --- a/ai_commit_msg/utils/git_utils.py +++ /dev/null @@ -1,30 +0,0 @@ -from ai_commit_msg.services.git_service import GitService -from ai_commit_msg.utils.utils import execute_cli_command -from ai_commit_msg.utils.logger import Logger - - -def handle_git_push(): - """ - Handle git push operation with upstream branch setting if needed. - Returns True if push was successful, False otherwise. - """ - logger = Logger() - current_branch = GitService.get_current_branch() - has_upstream = GitService.has_upstream_branch(current_branch) - - if has_upstream: - execute_cli_command(["git", "push"], output=True) - return True - - set_upstream = input( - f"No upstream branch found for '{current_branch}'. This will run: 'git push --set-upstream origin {current_branch}'. Set upstream? (y/n): " - ) - if set_upstream.lower() == "y": - execute_cli_command( - ["git", "push", "--set-upstream", "origin", current_branch], output=True - ) - logger.log(f"🔄 Upstream branch set for '{current_branch}'") - return True - else: - logger.log("Skipping push. You can set upstream manually") - return False