diff --git a/aider/main.py b/aider/main.py index 3958f2d38..c6c5e6091 100644 --- a/aider/main.py +++ b/aider/main.py @@ -440,8 +440,6 @@ def main(args=None, input=None, output=None): io.tool_output(repo_map) return - coder.dirty_commit() - if args.apply: content = io.read_text(args.apply) if content is None: @@ -450,6 +448,9 @@ def main(args=None, input=None, output=None): return io.tool_output("Use /help to see in-chat commands, run with --help to see cmd line args") + + coder.dirty_commit() + if args.message: io.tool_output() coder.run(with_message=args.message) diff --git a/aider/repo.py b/aider/repo.py index 330827adf..0016c332d 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -129,6 +129,15 @@ class AiderRepo: return commit_message def get_diffs(self, pretty, *args): + try: + commits = self.repo.iter_commits(self.repo.active_branch) + current_branch_has_commits = any(commits) + except git.exc.GitCommandError: + current_branch_has_commits = False + + if not current_branch_has_commits: + return "" + if pretty: args = ["--color"] + list(args) if not args: @@ -138,14 +147,6 @@ class AiderRepo: return diffs def show_diffs(self, pretty): - try: - current_branch_has_commits = any(self.repo.iter_commits(self.repo.active_branch)) - except git.exc.GitCommandError: - current_branch_has_commits = False - - if not current_branch_has_commits: - return "" - diffs = self.get_diffs(pretty) print(diffs) diff --git a/tests/test_main.py b/tests/test_main.py index e85c8439d..d5bc80d10 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -34,8 +34,9 @@ class TestMain(TestCase): def test_main_with_empty_dir_no_files_on_command(self): main(["--no-git"], input=DummyInput(), output=DummyOutput()) - def test_main_with_empty_dir_new_file(self): - main(["foo.txt", "--yes"], input=DummyInput(), output=DummyOutput()) + @patch("aider.repo.AiderRepo.get_commit_message", return_value="commit message!") + def test_main_with_empty_dir_new_file(self, get_commit_message): + main(["foo.txt", "--yes","--no-git"], input=DummyInput(), output=DummyOutput()) self.assertTrue(os.path.exists("foo.txt")) def test_main_with_empty_git_dir_new_file(self):