Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ Logs are written to `~/.codemcp/codemcp.log`. The log level can be set in a glob
```toml
[logger]
verbosity = "INFO" # Can be DEBUG, INFO, WARNING, ERROR, or CRITICAL

[git]
enabled = true # Set to false to disable all automatic Git operations
```

Logging is not configurable on a per project basis, but this shouldn't matter
Expand Down
15 changes: 15 additions & 0 deletions codemcp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"get_logger_verbosity",
"get_logger_path",
"get_line_endings_preference",
"git_operations_enabled",
]

# Default configuration values
Expand All @@ -31,6 +32,9 @@
"files": {
"line_endings": None, # Default to OS native or based on configs
},
"git": {
"enabled": True, # By default, git operations are enabled
},
}


Expand Down Expand Up @@ -136,3 +140,14 @@ def get_line_endings_preference() -> str | None:
"""
config = load_config()
return config["files"]["line_endings"]


def git_operations_enabled() -> bool:
"""Check if Git operations are enabled in the configuration.

Returns:
Boolean indicating whether Git operations are enabled.
Default is True if not specified in the config.
"""
config = load_config()
return config["git"]["enabled"]
11 changes: 11 additions & 0 deletions codemcp/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .access import check_edit_permission
from .async_file_utils import OpenTextMode
from .config import git_operations_enabled
from .git import commit_changes
from .line_endings import apply_line_endings, normalize_to_lf

Expand Down Expand Up @@ -55,6 +56,9 @@ async def check_git_tracking_for_existing_file(
) -> tuple[bool, str | None]:
"""Check if an existing file is tracked by git. Skips check for non-existent files.

If Git operations are disabled in the configuration, this function will skip
all Git checks and return success.

Args:
file_path: The absolute path to the file
chat_id: The unique ID to identify the chat session
Expand All @@ -70,6 +74,13 @@ async def check_git_tracking_for_existing_file(
# Normalize the path with tilde expansion
file_path = normalize_file_path(file_path)

# If Git operations are disabled, skip all Git checks
if not git_operations_enabled():
logging.debug(
"Git operations are disabled in config, skipping Git tracking check"
)
return True, None

# Check if the file exists
file_exists = os.path.exists(file_path)

Expand Down
26 changes: 26 additions & 0 deletions codemcp/git_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import re

from .config import git_operations_enabled
from .git_message import (
update_commit_message_with_description,
)
Expand Down Expand Up @@ -31,6 +32,9 @@ async def create_commit_reference(
in a reference (refs/codemcp/<chat_id>) without changing HEAD. We'll use
this to make the "real" commit once our first change happens.

If Git operations are disabled in the configuration, this function will
return a message indicating that Git operations are disabled.

Args:
path: The path to the file or directory to commit
chat_id: The unique ID of the current chat session
Expand All @@ -45,6 +49,16 @@ async def create_commit_reference(
subprocess.CalledProcessError: If a Git command fails
Exception: For other errors during the Git operations
"""
# Check if Git operations are enabled
if not git_operations_enabled():
log.info(
"Git operations are disabled in config, skipping create_commit_reference"
)
return (
"Git operations are disabled in configuration, commit reference not created",
"",
)

if not re.fullmatch(r"^[A-Za-z0-9-]+$", chat_id):
raise ValueError(f"Invalid chat_id format: {chat_id}")

Expand Down Expand Up @@ -173,6 +187,9 @@ async def commit_changes(
If commit_all is True, all changes in the repository will be committed.
When commit_all is True, path can be None.

If Git operations are disabled in the configuration, this function will
return success but with a message indicating that Git operations are disabled.

Args:
path: The path to the file or directory to commit
description: Commit message describing the change
Expand All @@ -190,6 +207,15 @@ async def commit_changes(
chat_id,
commit_all,
)

# Check if Git operations are enabled
if not git_operations_enabled():
log.info("Git operations are disabled in config, skipping commit_changes")
return (
True,
"Git operations are disabled in configuration, changes not committed",
)

# First, check if this is a git repository
if not await is_git_repository(path):
return False, f"Path '{path}' is not in a Git repository"
Expand Down
Loading