From 6adf151d838d943b1de06c7c9ffc492117d8e362 Mon Sep 17 00:00:00 2001 From: Sighery Date: Sun, 19 Jan 2020 19:09:03 +0100 Subject: [PATCH] Fix diff order to compare dst with src The current diffs are confusing, since they compare the source against the destination file. To make it less confusing: source is the file that contains modifications, and destination is the one to be overwritten. With the current order, it displays changes as if you were applying the destination file on the source file. This commit makes it so that it displays the changes it would need to apply source on destination. This is consistent with tools such as patch, that take first the destination file, and second the patch you're going to apply. Diffing should be done the same way, first the destination, second the file with the new changes. This is how other tools that provide diffs such as git also work. --- dotdrop/installer.py | 2 +- dotdrop/utils.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dotdrop/installer.py b/dotdrop/installer.py index a08cbc1..d3addad 100644 --- a/dotdrop/installer.py +++ b/dotdrop/installer.py @@ -444,7 +444,7 @@ class Installer: # fake the output for readability if not diff: return - self.log.log('diff \"{}\" VS \"{}\"'.format(src, dst)) + self.log.log('diff \"{}\" VS \"{}\"'.format(dst, src)) self.log.emph(diff) def _create_dirs(self, directory): diff --git a/dotdrop/utils.py b/dotdrop/utils.py index c4b82e2..3da940e 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -72,7 +72,7 @@ def shell(cmd, debug=False): def diff(src, dst, raw=True, opts='', debug=False): """call unix diff to compare two files""" - cmd = 'diff -r {} \"{}\" \"{}\"'.format(opts, src, dst) + cmd = 'diff -r {} \"{}\" \"{}\"'.format(opts, dst, src) _, out = run(shlex.split(cmd), raw=raw, debug=debug) return out