mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 22:04:59 +00:00
Only ask to commit when dirty files are touched
This commit is contained in:
parent
797372c69e
commit
6686ea1005
1 changed files with 26 additions and 1 deletions
|
@ -29,6 +29,7 @@ class Coder:
|
|||
abs_fnames = None
|
||||
repo = None
|
||||
last_aider_commit_hash = None
|
||||
last_asked_for_commit_time = 0
|
||||
|
||||
def __init__(self, main_model, fnames, pretty, history_file, show_diffs, auto_commits, yes):
|
||||
self.abs_fnames = set()
|
||||
|
@ -187,6 +188,17 @@ class Coder:
|
|||
except EOFError:
|
||||
return
|
||||
|
||||
def should_commit(self, is_commit_command):
|
||||
if not self.repo:
|
||||
return
|
||||
if not self.repo.is_dirty():
|
||||
return
|
||||
if is_commit_command:
|
||||
return
|
||||
if self.last_asked_for_commit_time >= self.get_last_modified():
|
||||
return
|
||||
return True
|
||||
|
||||
def run_loop(self):
|
||||
if self.pretty:
|
||||
self.console.rule()
|
||||
|
@ -199,7 +211,7 @@ class Coder:
|
|||
|
||||
is_commit_command = inp and inp.startswith("/commit")
|
||||
|
||||
if self.repo and self.repo.is_dirty() and not is_commit_command:
|
||||
if self.should_commit(is_commit_command):
|
||||
self.commit(ask=True, which="repo_files")
|
||||
|
||||
# files changed, move cur messages back behind the files messages
|
||||
|
@ -499,6 +511,8 @@ class Coder:
|
|||
"[bright_black]Commit before the chat proceeds? \[y/n/commit message]", # noqa: W605 E501
|
||||
default="y",
|
||||
).strip()
|
||||
self.last_asked_for_commit_time = self.get_last_modified()
|
||||
|
||||
self.console.print()
|
||||
|
||||
if res.lower() in ["n", "no"]:
|
||||
|
@ -528,6 +542,17 @@ class Coder:
|
|||
|
||||
return sorted(set(files))
|
||||
|
||||
def get_all_abs_files(self):
|
||||
files = self.get_all_relative_files()
|
||||
files = [os.path.abspath(os.path.join(self.root, path)) for path in files]
|
||||
return files
|
||||
|
||||
def get_last_modified(self):
|
||||
files = self.get_all_abs_files()
|
||||
if not files:
|
||||
return 0
|
||||
return max(Path(path).stat().st_mtime for path in files)
|
||||
|
||||
def confirm_ask(self, question, default=None):
|
||||
if self.yes:
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue