-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Tell git not to quote filenames in ls-files, to handle unicode filenames #85
Merged
Commits on Jul 11, 2023
-
Configuration menu - View commit details
-
Copy full SHA for c4e4d07 - Browse repository at this point
Copy the full SHA c4e4d07View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7c0ac4d - Browse repository at this point
Copy the full SHA 7c0ac4dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 2f4e206 - Browse repository at this point
Copy the full SHA 2f4e206View commit details -
aider: Added a test that creates a temporary directory, initializes a…
… git repository there, adds three empty files, creates a `Coder` object on that directory, and asserts that `coder.get_tracked_files()` returns the three filenames. # Aider chat conversation: USER: make a test which creates a tempdir and inits a git repo there. it should add 3 empty files with the filenames below. the test should create a Coder on that and make sure that coder.get_tracked_files() returns the 3 filenames. Here are the filenames: README.md doc/fänny_dirname/README.md doc/systemüberblick.md ASSISTANT: To create this test, we need to modify the `tests/test_coder.py` file. We will add a new test method named `test_get_tracked_files` in the `TestCoder` class. This method will create a temporary directory, initialize a git repository there, add three empty files, create a `Coder` object on that directory, and assert that `coder.get_tracked_files()` returns the three filenames. Here is the code change: ```python tests/test_coder.py <<<<<<< ORIGINAL if __name__ == "__main__": unittest.main() ======= def test_get_tracked_files(self): # Create a temporary directory tempdir = Path(tempfile.mkdtemp()) # Initialize a git repository in the temporary directory repo = git.Repo.init(tempdir) # Create three empty files and add them to the git repository filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"] for filename in filenames: (tempdir / filename).touch() repo.git.add(filename) # Create a Coder object on the temporary directory coder = Coder.create(models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", root=tempdir) # Assert that coder.get_tracked_files() returns the three filenames self.assertEqual(set(coder.get_tracked_files()), set(filenames)) if __name__ == "__main__": unittest.main() >>>>>>> UPDATED ``` This code assumes that the `Coder` class has a `get_tracked_files` method that returns the filenames of the tracked files in the git repository. If such a method does not exist, it should be implemented in the `Coder` class.
Configuration menu - View commit details
-
Copy full SHA for f1b61d4 - Browse repository at this point
Copy the full SHA f1b61d4View commit details -
Configuration menu - View commit details
-
Copy full SHA for db8fb97 - Browse repository at this point
Copy the full SHA db8fb97View commit details -
aider: Ensure parent directory exists before creating file in test_ge…
…t_tracked_files. # Aider chat conversation: USER: I ran this command: pytest -k test_get_tracked_files -s And got this output: ============================= test session starts ============================== platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0 rootdir: /Users/gauthier/Projects/aider configfile: pytest.ini collected 61 items / 60 deselected / 1 selected tests/test_coder.py F =================================== FAILURES =================================== _______________________ TestCoder.test_get_tracked_files _______________________ self = <tests.test_coder.TestCoder testMethod=test_get_tracked_files> def test_get_tracked_files(self): # Create a temporary directory tempdir = Path(tempfile.mkdtemp()) # Initialize a git repository in the temporary directory repo = git.Repo.init(tempdir) # Create three empty files and add them to the git repository filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"] for filename in filenames: > (tempdir / filename).touch() tests/test_coder.py:374: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = PosixPath('/var/folders/49/kxrdwwbx0h9bchx99397477c0000gn/T/tmpoowegb9x/doc/fänny_dirname/README.md') mode = 438, exist_ok = True def touch(self, mode=0o666, exist_ok=True): """ Create this file with the given access mode, if it doesn't exist. """ if exist_ok: # First try to bump modification time # Implementation note: GNU touch uses the UTIME_NOW option of # the utimensat() / futimens() functions. try: os.utime(self, None) except OSError: # Avoid exception chaining pass else: return flags = os.O_CREAT | os.O_WRONLY if not exist_ok: flags |= os.O_EXCL > fd = os.open(self, flags, mode) E FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/49/kxrdwwbx0h9bchx99397477c0000gn/T/tmpoowegb9x/doc/fänny_dirname/README.md' /usr/local/Cellar/[email protected]/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pathlib.py:1108: FileNotFoundError =========================== short test summary info ============================ FAILED tests/test_coder.py::TestCoder::test_get_tracked_files - FileNotFoundE... ======================= 1 failed, 60 deselected in 1.53s ======================= ASSISTANT: The error message indicates that the directory `doc/fänny_dirname` does not exist when the test tries to create the file `README.md` inside it. We need to ensure that the directory exists before creating the file. We can use the `mkdir` method of `Path` with the `parents=True` argument to create the directory and all its missing parents. Here is the updated code: ```python tests/test_coder.py <<<<<<< ORIGINAL def test_get_tracked_files(self): # Create a temporary directory tempdir = Path(tempfile.mkdtemp()) # Initialize a git repository in the temporary directory repo = git.Repo.init(tempdir) # Create three empty files and add them to the git repository filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"] for filename in filenames: (tempdir / filename).touch() repo.git.add(filename) # Create a Coder object on the temporary directory coder = Coder.create( models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", root=tempdir ) # Assert that coder.get_tracked_files() returns the three filenames self.assertEqual(set(coder.get_tracked_files()), set(filenames)) ======= def test_get_tracked_files(self): # Create a temporary directory tempdir = Path(tempfile.mkdtemp()) # Initialize a git repository in the temporary directory repo = git.Repo.init(tempdir) # Create three empty files and add them to the git repository filenames = ["README.md", "doc/fänny_dirname/README.md", "doc/systemüberblick.md"] for filename in filenames: file_path = tempdir / filename file_path.parent.mkdir(parents=True, exist_ok=True) file_path.touch() repo.git.add(str(file_path)) # Create a Coder object on the temporary directory coder = Coder.create( models.GPT4, None, io=InputOutput(), openai_api_key="fake_key", root=tempdir ) # Assert that coder.get_tracked_files() returns the three filenames self.assertEqual(set(coder.get_tracked_files()), set(filenames)) >>>>>>> UPDATED ``` This code creates the parent directory of each file before creating the file. It also converts the `Path` object to a string before passing it to `repo.git.add`, because the `git` library may not accept `Path` objects.
Configuration menu - View commit details
-
Copy full SHA for cb5d245 - Browse repository at this point
Copy the full SHA cb5d245View commit details -
Configuration menu - View commit details
-
Copy full SHA for 59a54f5 - Browse repository at this point
Copy the full SHA 59a54f5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 73f5fb0 - Browse repository at this point
Copy the full SHA 73f5fb0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 68c26a6 - Browse repository at this point
Copy the full SHA 68c26a6View commit details -
Configuration menu - View commit details
-
Copy full SHA for cccd0d1 - Browse repository at this point
Copy the full SHA cccd0d1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8d5f178 - Browse repository at this point
Copy the full SHA 8d5f178View commit details -
aider: Set the git user name and email in the
get_tracked_files
test.# Aider chat conversation: USER: set the git user name and email in the `get_tracked_files` test ASSISTANT: To set the git user name and email in the `get_tracked_files` test, we need to modify the `tests/test_coder.py` file. We will add two lines of code to set the git user name and email after initializing the git repository. Here is the change: ```python tests/test_coder.py <<<<<<< ORIGINAL # Initialize a git repository in the temporary directory repo = git.Repo.init(tempdir) ======= # Initialize a git repository in the temporary directory and set user name and email repo = git.Repo.init(tempdir) repo.config_writer().set_value("user", "name", "Test User").release() repo.config_writer().set_value("user", "email", "[email protected]").release() >>>>>>> UPDATED ``` This change sets the git user name to "Test User" and the email to "[email protected]".
Configuration menu - View commit details
-
Copy full SHA for 3e3694b - Browse repository at this point
Copy the full SHA 3e3694bView commit details -
Configuration menu - View commit details
-
Copy full SHA for c638d30 - Browse repository at this point
Copy the full SHA c638d30View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3294479 - Browse repository at this point
Copy the full SHA 3294479View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.