Commit graph

359 commits

Author SHA1 Message Date
Paul Gauthier
e8b041af96 aider: Added check to ensure remote head is only fetched when there is a remote origin.
# Context:
USER: the /undo command is throwing this error when the repo has no remote origin: Error: Unable to get the remote 'origin/scratch'.
ASSISTANT: I see the issue. The code is trying to get the remote head even when there is no remote origin. I will add a check to ensure that the remote head is only fetched when there is a remote origin. Here's the change:

```python
aider/commands.py
<<<<<<< ORIGINAL
        if has_origin:
            current_branch = self.coder.repo.active_branch.name
            try:
                remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}")
            except git.exc.GitCommandError:
                self.io.tool_error(f"Error: Unable to get the remote 'origin/{current_branch}'.")
                return
            if local_head == remote_head:
                self.io.tool_error(
                    "The last commit has already been pushed to the origin. Undoing is not"
                    " possible."
                )
                return
=======
        if has_origin:
            current_branch = self.coder.repo.active_branch.name
            try:
                remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}")
                if local_head == remote_head:
                    self.io.tool_error(
                        "The last commit has already been pushed to the origin. Undoing is not"
                        " possible."
                    )
                    return
            except git.exc.GitCommandError
^C KeyboardInterrupt
USER: no, has_origin needs to check if the *current branch* has an origin.
ASSISTANT: I understand now. I will modify the `has_origin` check to verify if the current branch has an origin. Here's the updated change:

```python
aider/commands.py
<<<<<<< ORIGINAL
        has_origin = any(remote.name == "origin" for remote in self.coder.repo.remotes)

        if has_origin:
            current_branch = self.coder.repo.active_branch.name
            try:
                remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}")
            except git.exc.GitCommandError:
                self.io.tool_error(f"Error: Unable to get the remote 'origin/{current_branch}'.")
                return
            if local_head == remote_head:
                self.io.tool_error(
                    "The last commit has already been pushed to the origin. Undoing is not"
                    " possible."
                )
                return
=======
        current_branch = self.coder.repo.active_branch.name
        try:
            remote_head = self.coder.repo.git.rev_parse(f"origin/{current_branch}")
            has_origin = True
        except git.exc.GitCommandError:
            has_origin = False

        if has_origin:
            if local_head == remote_head:
                self.io.tool_error(
                    "The last commit has already been pushed to the origin. Undoing is not"
                    " possible."
                )
                return
>>>>>>> UPDATED
```

This change will set `has_origin` to `True` only if the current branch has an origin, and it will handle the error accordingly.
2023-05-18 14:25:23 -07:00
Paul Gauthier
c9e35ebf83 moved Using git repo print to proper location 2023-05-18 12:26:26 -07:00
Paul Gauthier
4244eefb4a aider: Changed set_repo function to print git repo name relative to cwd.
# Context:
USER: when printing the git repo name, print it relative to cwd
ASSISTANT: To print the git repo name relative to the current working directory, you can modify the `set_repo` function in the `aider/coder.py` file. Here's the change:

```python
aider/coder.py
<<<<<<< ORIGINAL
        if num_repos == 0:
            self.io.tool_error("Files are not in a git repo.")
            return
        if num_repos > 1:
            self.io.tool_error("Files are in different git repos.")
            return

        # https://github.com/gitpython-developers/GitPython/issues/427
        repo = git.Repo(repo_paths.pop(), odbt=git.GitDB)

        self.root = repo.working_tree_dir

        self.io.tool("Using git repo:", self.repo.git_dir)
=======
        if num_repos == 0:
            self.io.tool_error("Files are not in a git repo.")
            return
        if num_repos > 1:
            self.io.tool_error("Files are in different git repos.")
            return

        # https://github.com/gitpython-developers/GitPython/issues/427
        repo = git.Repo(repo_paths.pop(), odbt=git.GitDB)

        self.root = repo.working_tree_dir

        rel_repo_dir = os.path.relpath(self.repo.git_dir, os.getcwd())
        self.io.tool("Using git repo:", rel_repo_dir)
>>>>>>> UPDATED
```

This change replaces `self.repo.git_dir` with `os.path.relpath(self.repo.git_dir, os.getcwd())` to display the git repo path relative to the current working directory.
2023-05-18 12:11:29 -07:00
Paul Gauthier
f28fc5b2b1 Changed command description for cmd_run. 2023-05-18 10:15:18 -07:00
Paul Gauthier
a525a1b543 Ask to add /run output to the chat 2023-05-18 10:13:50 -07:00
Paul Gauthier
0ade98dfff removed line numbers 2023-05-18 10:07:56 -07:00
Paul Gauthier
261f50c3ba removed line numbers 2023-05-18 10:07:39 -07:00
Paul Gauthier
01aafe1265 aider: Fixed indentation of cmd_run function in aider/commands.py.
# Context:
USER: remove all the line numbers fro the start of the lines, restoring proper indentation. only edit the lines that have line numbers.
ASSISTANT: ```python
aider/commands.py
<<<<<<< ORIGINAL
228     def cmd_run(self, args):
229         "Run the supplied command in a subprocess and combine stdout and stderr into a single string"
230         try:
231             parsed_args = shlex.split(args)
232             result = subprocess.run(parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
233             combined_output = result.stdout
233             print(combined_output)
234         except Exception as e:
235             self.io.tool_error(f"Error running command: {e}")
=======
    def cmd_run(self, args):
        "Run the supplied command in a subprocess and combine stdout and stderr into a single string"
        try:
            parsed_args = shlex.split(args)
            result = subprocess.run(parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
            combined_output = result.stdout
            print(combined_output)
        except Exception as e:
            self.io.tool_error(f"Error running command: {e}")
>>>>>>> UPDATED
```
2023-05-18 10:06:38 -07:00
Paul Gauthier
07da14d3c7 make line numbers optional 2023-05-18 10:04:13 -07:00
Paul Gauthier
7c807c8c53 aider: Changed cmd_run method to intermingle stdout and stderr using subprocess.PIPE for both and setting stderr=subprocess.STDOUT.
# Context:
USER: rather than concatenating stdin and stderr, can we get them intermingled like they would be shown in normal terminal output
ASSISTANT: Yes, you can intermingle stdout and stderr like they would be shown in normal terminal output by using the `subprocess.PIPE` for both stdout and stderr, and setting `stderr=subprocess.STDOUT`. We will modify the `cmd_run` method in the `aider/commands.py` file to implement this change.

Here are the changes to `aider/commands.py`:

```python
aider/commands.py
<<<<<<< ORIGINAL
231             parsed_args = shlex.split(args)
232             result = subprocess.run(parsed_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
233             combined_output = result.stdout + result.stderr
=======
231             parsed_args = shlex.split(args)
232             result = subprocess.run(parsed_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
233             combined_output = result.stdout
>>>>>>> UPDATED
```

These changes set `stderr=subprocess.STDOUT` in the `subprocess.run()` call, which will intermingle stdout and stderr like they would be shown in normal terminal output.
2023-05-18 10:02:44 -07:00
Paul Gauthier
aaf8c9e811 aider: Refactored cmd_run method to use shlex.split() instead of args.split() to correctly parse arguments, respecting quotes and other special characters.
# Context:
USER: is there a better way to parse args than args.split(), like a shell would, to respect quotes, etc
ASSISTANT: Yes, you can use the `shlex` module to split the arguments like a shell would, respecting quotes and other special characters. We will modify the `cmd_run` method in the `aider/commands.py` file to use `shlex.split()` instead of `args.split()`.

Here are the changes to `aider/commands.py`:

```python
aider/commands.py
<<<<<<< ORIGINAL
  3 import subprocess
=======
  3 import subprocess
  4 import shlex
>>>>>>> UPDATED
```

```python
aider/commands.py
<<<<<<< ORIGINAL
230         try:
231             result = subprocess.run(args.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
=======
230         try:
231             parsed_args = shlex.split(args)
232             result = subprocess.run(parsed_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
>>>>>>> UPDATED
```

These changes import the `shlex` module and replace `args.split()` with `shlex.split(args)` in the `cmd_run` method. This will correctly parse the arguments, respecting quotes and other special characters.
2023-05-18 10:01:24 -07:00
Paul Gauthier
f21857655e aider: Added cmd_run command to run a supplied command in a subprocess and combine stdout and stderr into a single string.
# Context:
USER: add a new cmd_run which runs the supplied line in a subprocess and collects stdout and stderr into strings
ASSISTANT: To add the `cmd_run` command, we will modify the `aider/commands.py` file. We will import the `
^C KeyboardInterrupt
USER: add a new cmd_run which runs the supplied line in a subprocess. combine stdout and stderr into a single string. print that.
ASSISTANT: To add the `cmd_run` command, we will modify the `aider/commands.py` file. We will import the `subprocess` module and create a new method called `cmd_run`. This method will run the supplied command in a subprocess, combine stdout and stderr into a single string, and print the result.

Here are the changes to `aider/commands.py`:

```python
aider/commands.py
<<<<<<< ORIGINAL
  1 import os
  2 import git
=======
  1 import os
  2 import git
  3 import subprocess
>>>>>>> UPDATED
```

```python
aider/commands.py
<<<<<<< ORIGINAL
228     def cmd_ls(self, args):
229         "List all known files and those included in the chat session"
230
231         files = self.coder.get_all_relative_files()
=======
228     def cmd_run(self, args):
229         "Run the supplied command in a subprocess and combine stdout and stderr into a single string"
230         try:
231             result = subprocess.run(args.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
232             combined_output = result.stdout + result.stderr
233             print(combined_output)
234         except Exception as e:
235             self.io.tool_error(f"Error running command: {e}")
236
237     def cmd_ls(self, args):
238         "List all known files and those included in the chat session"
239
240         files = self.coder.get_all_relative_files()
>>>>>>> UPDATED
```

These changes import the `subprocess` module, add the `cmd_run` method, and handle running the command and printing the combined stdout and stderr.
2023-05-18 09:59:48 -07:00
Paul Gauthier
33ae950467 Merge branch 'main' into pre-commit 2023-05-18 09:56:00 -07:00
Paul Gauthier
06a58b84bb noop 2023-05-18 09:55:50 -07:00
Paul Gauthier
4cbdb9b9ad Added a method to check if input is a command. 2023-05-18 09:54:54 -07:00
Paul Gauthier
271b0c837b Added a conditional to display a message only if input is not empty. 2023-05-18 08:54:19 -07:00
Paul Gauthier
891d5b2263 aider: Added line numbers to the output of the get_quoted_file function.
# Context:
USER: git get_files_content prefix each line with a line number, starting at 1, padded out like '  1'
ASSISTANT: To add line numbers to the `get_files_content` method, we will modify the method in the `aider/coder.py` file. We will read the file content line by line and add the line number with padding to each line.

Here's the change:

```python
aider/coder.py
<<<<<<< ORIGINAL
    def get_files_content(self, fnames=None):
        if not fnames:
            fnames = self.abs_fnames

        prompt = ""
        for fname in fnames:
            relative_fname = self.get_rel_fname(fname)
            prompt += utils.quoted_file(fname, relative_fname)
        return prompt
=======
    def get_files_content(self, fnames=None):

^C KeyboardInterrupt
USER: sorry, in get_quoted_file prefix each line with a line number, starting at 1, padded out like '  1'
ASSISTANT:
^C KeyboardInterrupt
USER: Please note that I shared content of these additional files: aider/utils.py
ASSISTANT: To add line
^C KeyboardInterrupt
USER: in get_quoted_file prefix each line with a line number, starting at 1, padded out like '  1'
ASSISTANT: To add line numbers to the `get_quoted_file` function in the `aider/utils.py` file, we will read the file content line by line and add the line number with padding to each line.

Here's the change:

```python
aider/utils.py
<<<<<<< ORIGINAL
def quoted_file(fname, display_fname):
    prompt = "\n"
    prompt += display_fname
    prompt += "\n```\n"
    prompt += Path(fname).read_text()
    prompt += "\n```\n"
    return prompt
=======
def quoted_file(fname, display_fname):
    prompt = "\n"
    prompt += display_fname
    prompt += "\n```\n"
    file_content = Path(fname).read_text()
    lines = file_content.splitlines()
    for i, line in enumerate(lines, start=1):
        prompt += f"{i:3d} {line}\n"
    prompt += "```\n"
    return prompt
>>>>>>> UPDATED
```

This change will add line numbers to the output of the `get_quoted_file` function, starting at 1 and padded out like '  1'.
2023-05-18 07:00:50 -07:00
Paul Gauthier
943084fba2 aider: Removed unused imports in aider/io.py.
# Context:
USER: aider/io.py:12:1: F401 'time' imported but unused
import time
^
aider/io.py:13:1: F401 'random' imported but unused
import random
^

ASSISTANT: I see that there are unused imports in the `aider/io.py` file. I will remove them.

```python
aider/io.py
<<<<<<< ORIGINAL
import time
import random
=======
>>>>>>> UPDATED
```
2023-05-17 18:26:15 -07:00
Paul Gauthier
d5f2bef29e aider: Import git module in aider/commands.py.
# Context:
USER: aider/commands.py:101:20: F821 undefined name 'git'
            except git.exc.GitCommandError:
                   ^

ASSISTANT: It seems like the `git` module is not imported in the `aider/commands.py` file. To fix this issue, we need to import the `git` module at the beginning of the file.

Here's the change to import the `git` module:

```python
aider/commands.py
<<<<<<< ORIGINAL
import os
from rich.prompt import Confirm
from prompt_toolkit.completion import Completion
from aider import prompts
=======
import os
import git
from rich.prompt import Confirm
from prompt_toolkit.completion import Completion
from aider import prompts
>>>>>>> UPDATED
```
2023-05-17 18:25:47 -07:00
Paul Gauthier
6e83df4c8d aider: Removed unused import of rich.text.Text in aider/commands.py.
# Context:
USER: aider/commands.py:2:1: F401 'rich.text.Text' imported but unused
from rich.text import Text
^

ASSISTANT: I will remove the unused import from the `aider/commands.py` file.

```python
aider/commands.py
<<<<<<< ORIGINAL
from rich.text import Text
from rich.prompt import Confirm
=======
from rich.prompt import Confirm
>>>>>>> UPDATED
```
2023-05-17 18:25:03 -07:00
Paul Gauthier
9a413d351d black formatting 2023-05-17 18:24:35 -07:00
Paul Gauthier
bdae74a9a8 Ask the user to retry their cmd if we interrupt with an autocommit 2023-05-17 16:19:15 -07:00
Paul Gauthier
cc0ee034f4 aider: Added a check to ensure that part appears in whole exactly once in try_dotdotdots.
# Context:
USER: in try_dotdotdots, after checking that part is in whole add a check that part is in whole exactly 1 time
ASSISTANT: ```python
aider/utils.py
<<<<<<< ORIGINAL
        if part not in whole:
            raise ValueError("No perfect matching chunk in edit block with ...")

        whole = whole.replace(part, replace)
=======
        if whole.count(part) != 1:
            raise ValueError("No perfect matching chunk in edit block with ... or part appears more than once")

        whole = whole.replace(part, replace, 1)
>>>>>>> UPDATED
```
2023-05-17 16:15:09 -07:00
Paul Gauthier
2e53e59cf3 aider: Changed print statement to show actual repo directory instead of working tree.
# Context:
USER: after Using git repo print the actual repo dir, not the working tree
ASSISTANT: To print the actual repo directory instead of the working tree, you can use the `git rev-parse --git-dir` command. I need to see the relevant code file where you want to implement this change.
^C KeyboardInterrupt
USER: Please note that I shared content of these additional files: aider/coder.py
ASSISTANT: I apologize for the oversight. Here's the change to print the actual repo directory instead of the working tree in the `aider/coder.py` file:

```python
aider/coder.py
<<<<<<< ORIGINAL
        if self.repo:
            self.io.tool("Using git repo:", self.root)
=======
        if self.repo:
            self.io.tool("Using git repo:", self.repo.git_dir)
>>>>>>> UPDATED
```

This change will print the actual repo directory when a suitable git repo is found.
2023-05-17 16:11:40 -07:00
Paul Gauthier
d0c729469d Added logging for when a suitable git repo is found. 2023-05-17 16:10:38 -07:00
Paul Gauthier
4ce6e279d3 Removed the canned_input method and commented out related code. 2023-05-17 15:24:40 -07:00
Paul Gauthier
7dc406d0b4 Print aider in lowercase 2023-05-17 15:22:34 -07:00
Paul Gauthier
a9511b85b6 Added log_only parameter to io.tool function call. 2023-05-17 15:21:21 -07:00
Paul Gauthier
bca4674e07 aider: Added a log_only parameter to tool() to allow emitting only to the log.
# Context:
USER: add a log_only=False param to tool() which only emits to the log, not to the scren
ASSISTANT: ```python
aider/io.py
<<<<<<< ORIGINAL
    def tool(self, *messages):
        if messages:
            hist = " ".join(messages)
            hist = f"{hist.strip()}"
            self.append_chat_history(hist, linebreak=True, blockquote=True)

        messages = list(map(Text, messages))
        self.console.print(*messages)
=======
    def tool(self, *messages, log_only=False):
        if messages:
            hist = " ".join(messages)
            hist = f"{hist.strip()}"
            self.append_chat_history(hist, linebreak=True, blockquote=True)

        if not log_only:
            messages = list(map(Text, messages))
            self.console.print(*messages)
>>>>>>> UPDATED
```
2023-05-17 15:20:52 -07:00
Paul Gauthier
fc1dac4ac3 log the cmd line to the chat history 2023-05-17 13:47:34 -07:00
Paul Gauthier
6ea9085eec updated md chat log format 2023-05-17 13:45:27 -07:00
Paul Gauthier
11c0dd89d9 Renamed getinput -> io 2023-05-17 13:41:58 -07:00
Paul Gauthier
b0a5c5b03d Refactor get_diffs method to accept variable number of arguments and fix get_diffs calls. 2023-05-15 14:18:57 -07:00
Paul Gauthier
d59c821019 aider: Modified cmd_diff to call self.coder.get_diffs.
# Context:
USER: have cmd_diff call self.coder.get_diffs
ASSISTANT: I will modify the `cmd_diff` method in the `aider/commands.py` file to call `self.coder.get_diffs` instead of directly calling the `git diff` command.

```python
aider/commands.py
<<<<<<< ORIGINAL
        if self.coder.pretty:
            diff = self.coder.repo.git.diff(commits, "--color", self.coder.last_aider_commit_hash)
        else:
            diff = self.coder.repo.git.diff(commits, self.coder.last_aider_commit_hash)
=======
        diff = self.coder.get_diffs(commits, self.coder.last_aider_commit_hash)
        if self.coder.pretty:
            diff = self.coder.repo.git.diff(commits, "--color", self.coder.last_aider_commit_hash)
        else:
            diff = self.coder.repo.git.diff(commits, self.coder.last_aider_commit_hash)
>>>>>>> UPDATED
```

Please review the changes and let me know if you have any questions or need further modifications.
2023-05-15 14:17:02 -07:00
Paul Gauthier
9ec43b4ee0 finished refactoring get_diffs 2023-05-15 14:15:53 -07:00
Paul Gauthier
076003310e aider: Refactored the if pretty: block in the get_dirty_files_and_diffs method into a separate method called get_diffs that takes relative_fname as an argument and accesses self.repo and self.pretty directly.
# Context:
USER: refactor the if pretty: repo.git.diff block into a method
ASSISTANT: I will refactor the `if pretty:` block in the `get_dirty_files_and_diffs` method into a separate method. Here's the plan:

1. Create a new method called `get_diffs` that takes `repo`, `relative_fname`, and `pretty` as arguments.
2. Move the `if pretty:` block from the `get_dirty_files_and_diffs` method to the new `get_diffs` method.
3. Replace the `if pretty:` block in the `get_dirty_files_and_diffs` method with a call to the new `get_diffs` method.

Here are the changes:

```python
aider/coder.py
<<<<<<< ORIGINAL
        def get_dirty_files_and_diffs(file_list):
            diffs = ""
            relative_dirty_files = []
            for fname in file_list:
                relative_fname = self
^C KeyboardInterrupt
USER: have the new method access self.repo and self.pretty; not as args
ASSISTANT: I will refactor the `if pretty:` block in the `get_dirty_files_and_diffs` method into a separate method called `get_diffs` that takes `relative_fname` as an argument and accesses `self.repo` and `self.pretty` directly. Here's the plan:

1. Create a new method called `get_diffs` that takes `relative_fname` as an argument.
2. Move the `if pretty:` block from the `get_dirty_files_and_diffs` method to the new `get_diffs` method.
3. Replace the `if pretty:` block in the `get_dirty_files_and_diffs` method with a call to the new `get_diffs` method.

Here are the changes:

```python
aider/coder.py
<<<<<<< ORIGINAL
        def get_dirty_files_and_diffs(file_list):
            diffs = ""
            relative_dirty_files = []
            for fname in file_list:
                relative_fname = self.get_rel_fname(fname)
                relative_dirty_files.append(relative_fname)

                try:
                    current_branch_commit_count = len(list(repo.iter_commits(repo.active_branch)))
                except git.exc.GitCommandError:
                    current_branch_commit_count = None

                if not current_branch_commit_count:
                    continue

                if self.pretty:
                    these_diffs = repo.git.diff("HEAD", "--color", "--", relative_fname)
                else:
                    these_diffs = repo.git.diff("HEAD", relative_fname)

                if these_diffs:
                    diffs += these_diffs + "\n"
=======
        def get_diffs(self, relative_fname):
            if self.pretty:
                these_diffs = self.repo.git.diff("HEAD", "--color", "--", relative_fname)
            else:
                these_diffs = self.repo.git.diff("HEAD", relative_fname)
            return these_diffs

        def get_dirty_files_and_diffs(self, file_list):
            diffs = ""
            relative_dirty_files = []
            for fname in file_list:
                relative_fname = self.get_rel_fname(fname)
                relative_dirty_files.append(relative_fname)

                try:
                    current_branch_commit_count = len(list(self.repo.iter_commits(self.repo.active_branch)))
                except git.exc.GitCommandError:
                    current_branch_commit_count = None

                if not current_branch_commit_count:
                    continue

                these_diffs = self.get_diffs(relative_fname)

                if these_diffs:
                    diffs += these_diffs + "\n"
>>>>>>> UPDATED
```
2023-05-15 14:10:57 -07:00
Paul Gauthier
37a4c47282 Refactor apply_updates method to return edit_error instead of err. 2023-05-14 15:01:50 -07:00
Paul Gauthier
28533ad23e aider: Refactored try/except block around self.update_files() call into a new method called apply_updates(). 2023-05-14 14:57:57 -07:00
Paul Gauthier
3374ae19be wip: Changed prompt messages to use proper grammar and formatting. 2023-05-14 14:54:55 -07:00
Paul Gauthier
0c05e3d957 Handle case where part="" and replace is non-empty 2023-05-14 11:07:22 -07:00
Paul Gauthier
e9debe71e8 Attempt to honot edit blocks which elide content using ... 2023-05-14 11:00:45 -07:00
Paul Gauthier
ed138d1940 changed output if dryrun 2023-05-14 10:16:43 -07:00
Paul Gauthier
ab68022fb9 wip: Added a dry-run option to do_replace function. 2023-05-14 10:15:08 -07:00
Paul Gauthier
0b8690654e aider: Added dry_run parameter to do_replace function and passed it from Coder class.
# Context:
USER: pass dry run into do_replace and only write to the file if false
ASSISTANT: To implement this change, we need to modify the `do_replace` function in the `aider/utils.py` file. We will add a new parameter `dry_run` to the function and only write to the file if `dry_run` is `False`.

Here's the change:

```python
aider/utils.py
<<<<<<< ORIGINAL
def do_replace(fname, before_text, after_text):
=======
def do_replace(fname, before_text, after_text, dry_run=False):
>>>>>>> UPDATED
    before_text = strip_quoted_wrapping(before_text, fname)
    after_text = strip_quoted_wrapping(after_text, fname)
    fname = Path(fname)

    # does it want to make a new file?
    if not fname.exists() and not before_text.strip():
        fname.touch()

    content = fname.read_text()

    if not before_text.strip():
        if content:
            new_content = content + after_text
        else:
            # first populating an empty file
            new_content = after_text
    else:
        new_content = replace_most_similar_chunk(content, before_text, after_text)
        if not new_content:
            return

    if not dry_run:
        fname.write_text(new_content)
    return True
```

Now, you need to pass the `dry_run` parameter from the `Coder` class in the `aider/coder.py` file to the `do_replace` function. Here's the change:

```python
aider/coder.py
<<<<<<< ORIGINAL
if utils.do_replace(full_path, original, updated):
=======
if utils.do_replace(full_path, original, updated, self.dry_run):
>>>>>>> UPDATED
    self.io.tool(f"Applied edit to {path}")
else:
    self.io.tool_error(f"Failed to apply edit to {path}")
```

These changes will ensure that the file is only written to when `dry_run` is `False`.
2023-05-14 10:14:20 -07:00
Paul Gauthier
a8acca9366 aider: Added a --dry-run argument to the main.py file and passed it to the Coder class, setting the self.dry_run attribute in the Coder class.
# Context:
USER: add a --dry-run arg, no env, default false. pass it into Coder and set self.dry_run
ASSISTANT: I will add a `--dry-run` argument to the `main.py` file and pass it to the `Coder` class. Then, I will set the `self.dry_run` attribute in the `Coder` class.

Here are the changes:

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--show-diffs",
        action="store_true",
        help=f"Show diffs when committing changes (default: False, ${env_prefix}SHOW_DIFFS)",
        default=bool(int(os.environ.get(f"{env_prefix}SHOW_DIFFS", 0))),
    )
=======
    parser.add_argument(
        "--dry-run",
        action="store_true",
        help="Perform a dry run without applying changes (default: False)",
        default=False,
    )
    parser.add_argument(
        "--show-diffs",
        action="store_true",
        help=f"Show diffs when committing changes (default: False, ${env_prefix}SHOW_DIFFS)",
        default=bool(int(os.environ.get(f"{env_prefix}SHOW_DIFFS", 0))),
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    io = InputOutput(
        args.pretty,
        args.yes,
        args.input_history_file,
        args.chat_history_file,
        input=input,
        output=output,
    )

    coder = Coder(
        args.model,
        fnames,
        pretty,
        args.show_diffs,
        args.auto_commits,
        io,
    )
=======
    io = InputOutput(
        args.pretty,
        args.yes,
        args.input_history_file,
        args.chat_history_file,
        input=input,
        output=output,
    )

    coder = Coder(
        args.model,
        fnames,
        pretty,
        args.show_diffs,
        args.auto_commits,
        io,
        args.dry_run,
    )
>>>>>>> UPDATED
```

```python
aider/coder.py
<<<<<<< ORIGINAL
    def __init__(self, main_model, fnames, pretty, show_diffs, auto_commits, io):
        self.abs_fnames = set()

        self.io = io

        self.auto_commits = auto_commits
=======
    def __init__(self, main_model, fnames, pretty, show_diffs, auto_commits, io, dry_run):
        self.abs_fnames = set()

        self.io = io

        self.auto_commits = auto_commits
        self.dry_run = dry_run
>>>>>>> UPDATED
```

Please review the changes and let me know if you need any further modifications.
2023-05-14 10:06:16 -07:00
Paul Gauthier
708653290f Creating empty file 2023-05-14 09:09:37 -07:00
Paul Gauthier
3f26a3ec05 main prompt in normal mixed case 2023-05-14 08:19:32 -07:00
Paul Gauthier
70ea500783 improved --no-auto-commits support 2023-05-14 07:37:04 -07:00
Paul Gauthier
78b1296e0e Added auto_commit method to Coder class. 2023-05-14 07:23:20 -07:00
Paul Gauthier
9c2f8e22d8 wip: Refactor file mentions check in Coder class to strip away all kinds of quotes and drop sentence punctuation. 2023-05-13 15:21:26 -07:00