mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 06:44:59 +00:00
ensure we diff properly in all cases, with tests #191
This commit is contained in:
parent
7924900bc4
commit
a1da6cab24
2 changed files with 75 additions and 8 deletions
|
@ -126,13 +126,35 @@ class GitRepo:
|
|||
return commit_message
|
||||
|
||||
def get_diffs(self, pretty, *args):
|
||||
# we always want diffs of working-dir + index versus repo
|
||||
args = ["--cached"] + list(args)
|
||||
args = list(args)
|
||||
|
||||
# if args are specified, just add --pretty if needed
|
||||
if args:
|
||||
if pretty:
|
||||
args = ["--color"] + args
|
||||
return self.repo.git.diff(*args)
|
||||
|
||||
# otherwise, we always want diffs of index and working dir
|
||||
|
||||
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 pretty:
|
||||
args = ["--color"] + list(args)
|
||||
args = ["--color"]
|
||||
|
||||
if current_branch_has_commits:
|
||||
# if there is a HEAD, just diff against it to pick up index + working
|
||||
args += ["HEAD"]
|
||||
return self.repo.git.diff(*args)
|
||||
|
||||
# diffs in the index
|
||||
diffs = self.repo.git.diff(*(args + ["--cached"]))
|
||||
# plus, diffs in the working dir
|
||||
diffs += self.repo.git.diff(*args)
|
||||
|
||||
diffs = self.repo.git.diff(*args)
|
||||
return diffs
|
||||
|
||||
def show_diffs(self, pretty):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue