Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable adding unstaged files when aider --commit is called from CLI #1812

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions aider/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ def run(self, inp):
# any method called cmd_xxx becomes a command automatically.
# each one must take an args param.

def cmd_commit(self, args=None):
def cmd_commit(self, args=None, from_cli=False):
"Commit edits to the repo made outside the chat (commit message optional)"
try:
self.raw_cmd_commit(args)
self.raw_cmd_commit(args, from_cli=from_cli)
except ANY_GIT_ERROR as err:
self.io.tool_error(f"Unable to complete commit: {err}")

def raw_cmd_commit(self, args=None):
def raw_cmd_commit(self, args=None, from_cli=False):
if not self.coder.repo:
self.io.tool_error("No git repository found.")
return
Expand All @@ -256,7 +256,7 @@ def raw_cmd_commit(self, args=None):
return

commit_message = args.strip() if args else None
self.coder.repo.commit(message=commit_message)
self.coder.repo.commit(message=commit_message, add_unstaged=(not from_cli))

def cmd_lint(self, args="", fnames=None):
"Lint and fix in-chat files or all dirty files if none in chat"
Expand Down
2 changes: 1 addition & 1 deletion aider/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def get_io(pretty):
if args.dry_run:
io.tool_output("Dry run enabled, skipping commit.")
else:
coder.commands.cmd_commit()
coder.commands.cmd_commit(from_cli=True)

if args.lint or args.test or args.commit:
return
Expand Down
4 changes: 2 additions & 2 deletions aider/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __init__(
if aider_ignore_file:
self.aider_ignore_file = Path(aider_ignore_file)

def commit(self, fnames=None, context=None, message=None, aider_edits=False):
def commit(self, fnames=None, context=None, message=None, aider_edits=False, add_unstaged=True):
if not fnames and not self.repo.is_dirty():
return

Expand Down Expand Up @@ -130,7 +130,7 @@ def commit(self, fnames=None, context=None, message=None, aider_edits=False):
except ANY_GIT_ERROR as err:
self.io.tool_error(f"Unable to add {fname}: {err}")
cmd += ["--"] + fnames
else:
elif add_unstaged:
cmd += ["-a"]

original_user_name = self.repo.config_reader().get_value("user", "name")
Expand Down