path: root/git-difftool.perl
diff options
authorTim Henigan <>2012-07-19 08:27:09 (GMT)
committerJunio C Hamano <>2012-07-19 17:33:44 (GMT)
commit05df532655e14ba351b4ee8a0acd8f190ed0b745 (patch)
tree5ce5e4b21605980b0b69f69d5abb9a689b6936c0 /git-difftool.perl
parent0ce2e396ee9fb0fa07e8381b338e49859dbf03db (diff)
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 <> Signed-off-by: David Aguilar <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'git-difftool.perl')
1 files changed, 5 insertions, 2 deletions
diff --git a/git-difftool.perl b/git-difftool.perl
index ae1e052..c079854 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -15,6 +15,7 @@ use strict;
use warnings;
use File::Basename qw(dirname);
use File::Copy;
+use File::Compare;
use File::Find;
use File::stat;
use File::Path qw(mkpath);
@@ -336,8 +337,10 @@ if (defined($dirdiff)) {
# files were modified during the diff, then the changes
# should be copied back to the working tree
for my $file (@working_tree) {
- copy("$b/$file", "$workdir/$file") or die $!;
- chmod(stat("$b/$file")->mode, "$workdir/$file") or die $!;
+ if (-e "$b/$file" && compare("$b/$file", "$workdir/$file")) {
+ copy("$b/$file", "$workdir/$file") or die $!;
+ chmod(stat("$b/$file")->mode, "$workdir/$file") or die $!;
+ }
} else {
if (defined($prompt)) {