difftool --dir-diff: allow changing any clean working tree file
The temporary directory prepared by "difftool --dir-diff" to show the result of a change can be modified by the user via the tree diff program, and we try hard not to lose changes to them after tree diff program returns to us. However, the set of files to be copied back is computed differently between --symlinks and --no-symlinks modes. The former checks all paths that start out as identical to the working tree file, while the latter checks paths that already had a local modification in the working tree, allowing changes made in the tree diff program to paths that did not have any local change to be lost. Signed-off-by: Kenichi Saita <nitoyon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kenichi Saita committed
May 30, 2013 at 01:01 UTC
32eaf1de7f79c4ba09f3de3261c84e52e0a67af5
2 files changed
+21
-7
git-difftool.perl
+2
-7
@@ -85,13 +85,9 @@ sub exit_cleanup
85
86
sub use_wt_file
87
{
88
- my ($repo, $workdir, $file, $sha1, $symlinks) = @_;
88
+ my ($repo, $workdir, $file, $sha1) = @_;
89
my $null_sha1 = '0' x 40;
90
91
- if ($sha1 ne $null_sha1 and not $symlinks) {
92
- return 0;
93
- }
94
-
91
if (! -e "$workdir/$file") {
92
# If the file doesn't exist in the working tree, we cannot
93
# use it.
@@ -213,8 +209,7 @@ EOF
209
210
if ($rmode ne $null_mode) {
211
my ($use, $wt_sha1) = use_wt_file($repo, $workdir,
216
- $dst_path, $rsha1,
217
- $symlinks);
212
+ $dst_path, $rsha1);
213
if ($use) {
214
push @working_tree, $dst_path;
215
$wtindex .= "$rmode $wt_sha1\t$dst_path\0";
t/t7800-difftool.sh
+19
@@ -385,6 +385,25 @@ test_expect_success PERL,SYMLINKS 'difftool --dir-diff --symlink without unstage
385
test_cmp actual expect
386
'
387
388
+write_script modify-right-file <<\EOF
389
+echo "new content" >"$2/file"
390
+EOF
391
+
392
+run_dir_diff_test 'difftool --dir-diff syncs worktree with unstaged change' '
393
+ test_when_finished git reset --hard &&
394
+ echo "orig content" >file &&
395
+ git difftool -d $symlinks --extcmd "$(pwd)/modify-right-file" branch &&
396
+ echo "new content" >expect &&
397
+ test_cmp expect file
398
+'
399
+
400
+run_dir_diff_test 'difftool --dir-diff syncs worktree without unstaged change' '
401
+ test_when_finished git reset --hard &&
402
+ git difftool -d $symlinks --extcmd "$(pwd)/modify-right-file" branch &&
403
+ echo "new content" >expect &&
404
+ test_cmp expect file
405
+'
406
+
407
write_script modify-file <<\EOF
408
echo "new content" >file
409
EOF