Skip to content
This repository was archived by the owner on Jul 2, 2019. It is now read-only.

Commit 32eaf1d

Browse files
nitoyongitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent edca415 commit 32eaf1d

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

git-difftool.perl

+2-7
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,9 @@ sub exit_cleanup
8585

8686
sub use_wt_file
8787
{
88-
my ($repo, $workdir, $file, $sha1, $symlinks) = @_;
88+
my ($repo, $workdir, $file, $sha1) = @_;
8989
my $null_sha1 = '0' x 40;
9090

91-
if ($sha1 ne $null_sha1 and not $symlinks) {
92-
return 0;
93-
}
94-
9591
if (! -e "$workdir/$file") {
9692
# If the file doesn't exist in the working tree, we cannot
9793
# use it.
@@ -213,8 +209,7 @@ sub setup_dir_diff
213209

214210
if ($rmode ne $null_mode) {
215211
my ($use, $wt_sha1) = use_wt_file($repo, $workdir,
216-
$dst_path, $rsha1,
217-
$symlinks);
212+
$dst_path, $rsha1);
218213
if ($use) {
219214
push @working_tree, $dst_path;
220215
$wtindex .= "$rmode $wt_sha1\t$dst_path\0";

t/t7800-difftool.sh

+19
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,25 @@ test_expect_success PERL,SYMLINKS 'difftool --dir-diff --symlink without unstage
385385
test_cmp actual expect
386386
'
387387

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+
388407
write_script modify-file <<\EOF
389408
echo "new content" >file
390409
EOF

0 commit comments

Comments
 (0)