Skip to content

Commit

Permalink
Disable adding unstaged files when aider --commit is called from CLI
Browse files Browse the repository at this point in the history
Currently, running `aider --commit` will add all unstaged files and then
create a commit. However, a useful workflow using aider may involve just
staging a few files and then calling `aider --commit` to commit those
files.

In fact, I believe this to be the sensible default. Therefore, this PR
passes the information whether the commit was triggered explicitly from
the command line interface (CLI), or rather internally later. If it was
triggered from CLI, then after this change aider will not append the
`-a` flag to the `git commit` command.
  • Loading branch information
RomeoV committed Sep 29, 2024
1 parent cc01313 commit a875442
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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

0 comments on commit a875442

Please sign in to comment.