Skip to content

Commit 1d1d1b0

Browse files
committed
File diff: preserve arguments in headers
Unless one path is absolute and the other is relative. In that case, show both paths up to but excluding their common prefix.
1 parent 86ac69b commit 1d1d1b0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

diff/diff.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ class Diff:
8686
"""
8787

8888
def __init__(self, left: str, right: str):
89-
self._left_directory, self._right_directory = Path(left), Path(right)
89+
self._left_directory, self._right_directory = Path(left).absolute(), Path(right).absolute()
9090
if self._left_directory.is_file() and self._right_directory.is_file():
9191
self._left_right_file_mapping = {self._left_directory: self._right_directory}
9292
self._left_files, self._right_files = set(), set()
93-
self._left_directory, self._right_directory = self._left_directory.parent, self._right_directory.parent
93+
self._left_directory = Path(os.path.commonprefix([self._left_directory, self._right_directory]))
94+
self._right_directory = self._left_directory
9495
elif self._left_directory.is_dir() and self._right_directory.is_dir():
9596
self._matcher = difflib.SequenceMatcher(isjunk=None, autojunk=False)
9697
self._left_right_file_mapping = (

0 commit comments

Comments
 (0)