Skip to content

Commit 05df532

Browse files
thenigangitster
authored andcommitted
difftool: only copy back files modified during directory diff
When 'difftool --dir-diff' is used to compare working tree files, it always copies files from the tmp dir back to the working tree when the diff tool is closed, even if the files were not modified by the diff tool. This causes the file timestamp to change. Files should only be copied from the tmp dir back to the working copy if they were actually modified. Signed-off-by: Tim Henigan <tim.henigan@gmail.com> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 0ce2e39 commit 05df532

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

git-difftool.perl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use warnings;
1616
use File::Basename qw(dirname);
1717
use File::Copy;
18+
use File::Compare;
1819
use File::Find;
1920
use File::stat;
2021
use File::Path qw(mkpath);
@@ -336,8 +337,10 @@ sub write_to_file
336337
# files were modified during the diff, then the changes
337338
# should be copied back to the working tree
338339
for my $file (@working_tree) {
339-
copy("$b/$file", "$workdir/$file") or die $!;
340-
chmod(stat("$b/$file")->mode, "$workdir/$file") or die $!;
340+
if (-e "$b/$file" && compare("$b/$file", "$workdir/$file")) {
341+
copy("$b/$file", "$workdir/$file") or die $!;
342+
chmod(stat("$b/$file")->mode, "$workdir/$file") or die $!;
343+
}
341344
}
342345
} else {
343346
if (defined($prompt)) {

0 commit comments

Comments
 (0)