mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 05:54:25 +08:00
Fix an issue with creatin a diff, fixes #1757
This commit is contained in:
@@ -42,11 +42,17 @@ class ChangedFile:
|
||||
if self._from_path is None:
|
||||
from_p = ''
|
||||
else:
|
||||
from_p = self._from_path.relative_to(project_path)
|
||||
try:
|
||||
from_p = self._from_path.relative_to(project_path)
|
||||
except ValueError: # Happens it the path is not on th project_path
|
||||
from_p = self._from_path
|
||||
if self._to_path is None:
|
||||
to_p = ''
|
||||
else:
|
||||
to_p = self._to_path.relative_to(project_path)
|
||||
try:
|
||||
to_p = self._to_path.relative_to(project_path)
|
||||
except ValueError:
|
||||
to_p = self._to_path
|
||||
diff = difflib.unified_diff(
|
||||
old_lines, new_lines,
|
||||
fromfile=str(from_p),
|
||||
|
||||
@@ -70,3 +70,19 @@ def test_diff_without_ending_newline(Script):
|
||||
-a
|
||||
+c
|
||||
''')
|
||||
|
||||
|
||||
def test_diff_path_outside_of_project(Script):
|
||||
script = Script(
|
||||
code='foo = 1',
|
||||
path='/unknown_dir/file.py',
|
||||
project=jedi.get_default_project()
|
||||
)
|
||||
diff = script.rename(line=1, column=0, new_name='bar').get_diff()
|
||||
assert diff == dedent('''\
|
||||
--- /unknown_dir/file.py
|
||||
+++ /unknown_dir/file.py
|
||||
@@ -1 +1 @@
|
||||
-foo = 1
|
||||
+bar = 1
|
||||
''')
|
||||
|
||||
Reference in New Issue
Block a user