Skip to content

Commit

Permalink
feat: Add function to get git editor
Browse files Browse the repository at this point in the history
Add a new function `get_git_editor` in `git_utils.py` to retrieve the configured git editor or use 'vim' as the default. This function checks for the environment variables GIT_EDITOR and EDITOR, setting them accordingly. If not set, it defaults to 'vim' on non-Windows platforms and 'notepad.exe' on Windows platforms.

Update `user_interaction.py` to use this new function instead of directly getting the editor from environment variables.
  • Loading branch information
25077667 committed May 22, 2024
1 parent cfd86fc commit 59e0e22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,17 @@ def commit_full_text_message(repo_path: str, message: str) -> str:
except Exception as e:
logger.error(f"Failed to commit the message. Details: {e}")
sys.exit(1)


# get git core editor, if not set, use vim
def get_git_editor() -> str:
"""
Get the configured git editor or use 'vim' as the default.
"""
editor = os.getenv("GIT_EDITOR", os.getenv("EDITOR"))
if editor is None:
if sys.platform.startswith("win"):
editor = "notepad.exe"
else:
editor = "vim"
return editor
3 changes: 2 additions & 1 deletion src/user_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import tempfile
import subprocess
from .git_utils import get_git_editor


def get_user_input(prompt: str, default: str) -> str:
Expand All @@ -19,7 +20,7 @@ def edit_message(message: str) -> str:
"""
Open the provided message in a text editor and return the edited message.
"""
editor = os.getenv("EDITOR", "vim")
editor = get_git_editor()
with tempfile.NamedTemporaryFile(suffix=".tmp") as tf:
tf.write(message.encode())
tf.flush()
Expand Down

0 comments on commit 59e0e22

Please sign in to comment.