mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
black formatting
This commit is contained in:
parent
3c26f90269
commit
9a413d351d
4 changed files with 26 additions and 16 deletions
|
@ -86,7 +86,10 @@ class Commands:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.coder.repo.is_dirty():
|
if self.coder.repo.is_dirty():
|
||||||
self.io.tool_error("The repository has uncommitted changes. Please commit or stash them before undoing.")
|
self.io.tool_error(
|
||||||
|
"The repository has uncommitted changes. Please commit or stash them before"
|
||||||
|
" undoing."
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
local_head = self.coder.repo.git.rev_parse("HEAD")
|
local_head = self.coder.repo.git.rev_parse("HEAD")
|
||||||
|
@ -100,7 +103,10 @@ class Commands:
|
||||||
self.io.tool_error(f"Error: Unable to get the remote 'origin/{current_branch}'.")
|
self.io.tool_error(f"Error: Unable to get the remote 'origin/{current_branch}'.")
|
||||||
return
|
return
|
||||||
if local_head == remote_head:
|
if local_head == remote_head:
|
||||||
self.io.tool_error("The last commit has already been pushed to the origin. Undoing is not possible.")
|
self.io.tool_error(
|
||||||
|
"The last commit has already been pushed to the origin. Undoing is not"
|
||||||
|
" possible."
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
last_commit = self.coder.repo.head.commit
|
last_commit = self.coder.repo.head.commit
|
||||||
|
|
|
@ -1,27 +1,29 @@
|
||||||
import traceback
|
import traceback
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
def cvt(s):
|
def cvt(s):
|
||||||
if isinstance(s, str):
|
if isinstance(s, str):
|
||||||
return s
|
return s
|
||||||
try:
|
try:
|
||||||
return json.dumps(s, indent = 4)
|
return json.dumps(s, indent=4)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return str(s)
|
return str(s)
|
||||||
|
|
||||||
|
|
||||||
def dump(*vals):
|
def dump(*vals):
|
||||||
# http://docs.python.org/library/traceback.html
|
# http://docs.python.org/library/traceback.html
|
||||||
stack= traceback.extract_stack()
|
stack = traceback.extract_stack()
|
||||||
vars= stack[-2][3]
|
vars = stack[-2][3]
|
||||||
|
|
||||||
# strip away the call to dump()
|
# strip away the call to dump()
|
||||||
vars= '('.join(vars.split('(')[1:])
|
vars = "(".join(vars.split("(")[1:])
|
||||||
vars= ')'.join(vars.split(')')[:-1])
|
vars = ")".join(vars.split(")")[:-1])
|
||||||
|
|
||||||
vals= [cvt(v) for v in vals]
|
vals = [cvt(v) for v in vals]
|
||||||
has_newline = sum(1 for v in vals if '\n' in v)
|
has_newline = sum(1 for v in vals if "\n" in v)
|
||||||
if has_newline:
|
if has_newline:
|
||||||
print('%s:' % vars)
|
print("%s:" % vars)
|
||||||
print(', '.join(vals))
|
print(", ".join(vals))
|
||||||
else:
|
else:
|
||||||
print('%s:' % vars, ', '.join(vals))
|
print("%s:" % vars, ", ".join(vals))
|
||||||
|
|
|
@ -51,7 +51,9 @@ def try_dotdotdots(whole, part, replace):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if whole.count(part) != 1:
|
if whole.count(part) != 1:
|
||||||
raise ValueError("No perfect matching chunk in edit block with ... or part appears more than once")
|
raise ValueError(
|
||||||
|
"No perfect matching chunk in edit block with ... or part appears more than once"
|
||||||
|
)
|
||||||
|
|
||||||
whole = whole.replace(part, replace, 1)
|
whole = whole.replace(part, replace, 1)
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@ class TestMain(TestCase):
|
||||||
def test_main_with_empty_dir_no_files_on_command(self):
|
def test_main_with_empty_dir_no_files_on_command(self):
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
os.chdir(temp_dir)
|
os.chdir(temp_dir)
|
||||||
pipe_input = create_input(StringIO(''))
|
pipe_input = create_input(StringIO(""))
|
||||||
main([], input=pipe_input, output=DummyOutput())
|
main([], input=pipe_input, output=DummyOutput())
|
||||||
pipe_input.close()
|
pipe_input.close()
|
||||||
|
|
||||||
def test_main_with_empty_dir_new_file(self):
|
def test_main_with_empty_dir_new_file(self):
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
os.chdir(temp_dir)
|
os.chdir(temp_dir)
|
||||||
pipe_input = create_input(StringIO(''))
|
pipe_input = create_input(StringIO(""))
|
||||||
main(["foo.txt"], input=pipe_input, output=DummyOutput())
|
main(["foo.txt"], input=pipe_input, output=DummyOutput())
|
||||||
pipe_input.close()
|
pipe_input.close()
|
||||||
self.assertTrue(os.path.exists("foo.txt"))
|
self.assertTrue(os.path.exists("foo.txt"))
|
||||||
|
@ -29,7 +29,7 @@ class TestMain(TestCase):
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
os.chdir(temp_dir)
|
os.chdir(temp_dir)
|
||||||
subprocess.run(["git", "init"], cwd=temp_dir)
|
subprocess.run(["git", "init"], cwd=temp_dir)
|
||||||
pipe_input = create_input(StringIO(''))
|
pipe_input = create_input(StringIO(""))
|
||||||
main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
|
main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
|
||||||
pipe_input.close()
|
pipe_input.close()
|
||||||
self.assertTrue(os.path.exists("foo.txt"))
|
self.assertTrue(os.path.exists("foo.txt"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue