Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit a5aca6e

Browse files
committed
Merge branch 'tr/diff-submodule-no-reuse-worktree' into maint
"git diff --external-diff" incorrectly fed the submodule directory in the working tree to the external diff driver when it knew it is the same as one of the versions being compared. * tr/diff-submodule-no-reuse-worktree: diff: do not reuse_worktree_file for submodules
2 parents 1f56977 + aba4727 commit a5aca6e

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

diff.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,8 +2845,9 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
28452845
remove_tempfile_installed = 1;
28462846
}
28472847

2848-
if (!one->sha1_valid ||
2849-
reuse_worktree_file(name, one->sha1, 1)) {
2848+
if (!S_ISGITLINK(one->mode) &&
2849+
(!one->sha1_valid ||
2850+
reuse_worktree_file(name, one->sha1, 1))) {
28502851
struct stat st;
28512852
if (lstat(name, &st) < 0) {
28522853
if (errno == ENOENT)

t/t4020-diff-external.sh

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,45 @@ keep_only_cr () {
226226
}
227227

228228
test_expect_success 'external diff with autocrlf = true' '
229-
git config core.autocrlf true &&
229+
test_config core.autocrlf true &&
230230
GIT_EXTERNAL_DIFF=./fake-diff.sh git diff &&
231231
test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
232232
'
233233

234234
test_expect_success 'diff --cached' '
235+
test_config core.autocrlf true &&
235236
git add file &&
236237
git update-index --assume-unchanged file &&
237238
echo second >file &&
238239
git diff --cached >actual &&
239240
test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
240241
'
241242

243+
test_expect_success 'clean up crlf leftovers' '
244+
git update-index --no-assume-unchanged file &&
245+
rm -f file* &&
246+
git reset --hard
247+
'
248+
249+
test_expect_success 'submodule diff' '
250+
git init sub &&
251+
( cd sub && test_commit sub1 ) &&
252+
git add sub &&
253+
test_tick &&
254+
git commit -m "add submodule" &&
255+
( cd sub && test_commit sub2 ) &&
256+
write_script gather_pre_post.sh <<-\EOF &&
257+
echo "$1 $4" # path, mode
258+
cat "$2" # old file
259+
cat "$5" # new file
260+
EOF
261+
GIT_EXTERNAL_DIFF=./gather_pre_post.sh git diff >actual &&
262+
cat >expected <<-EOF &&
263+
sub 160000
264+
Subproject commit $(git rev-parse HEAD:sub)
265+
Subproject commit $(cd sub && git rev-parse HEAD)
266+
EOF
267+
test_cmp expected actual
268+
'
269+
242270
test_done

0 commit comments

Comments
 (0)